All Apps   Steps+   Twitter   Contact   RSS  

Now that Swift thas been open sourced - the ability to make a backend in Swift is much most accessible (since you can now run it on Linux).

Something I think Apple should do, is implement garbage collection for Swift. Even though the recent history of Apple with regards to garbage collection, didn't end well for Objective-C.

First here are the higher level reasons I think a garbage collector should be added by Apple:
  1. Memory leaks become a much larger problem in server side software
  2. I believe someone will have a fork of Swift that implements garbage collection
The reason I think memory leaks are a larger issues on servers, is that processes on servers tend to live longer (potentially 24/7 for potentially months or years) - if you are leaking even a small amount of data - if it is over and over, eventually your server will run out of memory which means you will either have to reboot your server or restart your process. This would also causes performance degradation of the whole system as time goes on and more is leaked.

While restarting the server or process whenever you run out of memory could be an okay solution, it hurts your rate of uptime - which is also far more important for server side software.

Another concern (which is far harder to provide much evidence of unfortunately), is that if a popular fork of Swift is one that implements garbage collection while the official one does not. The addition of garbage collection to a language is a relatively large project that would probably require a fair amount of changes to the Swift runtime - which could drastically reduce the portability of Swift code potentially more than other changes might.

Another set of concerns that I have are more related to day to day annoyances that I run into. For example - delegation is a common pattern in Cocoa and Cocoa apps, something like this:

Because we have to instruct the compiler what the retain counting semantics we have these two issues:
  1. Our delegate must be
    (as an expectation of delegation is the delegate could be the same object that owns the object without causing a retain cycle).
  2. Since our delegate must be
    , the protocol must qualify that types that conform to it must be a class - so the delegate can not be a value type.
  3. We also are forced to make it both optional and mutable (because ARC sets it to
    ). This means there is an additional state you have to account for.
Instead of using
you might suggest using
- while this would prevent retain cycles, it could also leave a dangling pointer if that object is released; which would crash if you tried to call any methods on it or access any properties.

Ideally - I would love to be able to write this like:

In conclusion - I hope that someday we get garbage collection for Swift as I think it improves the viability of Swift on the server and provides a better programming model for software written in Swift.