bustoutsolutions / siesta

The civilized way to write REST API clients for iOS / macOS
https://bustoutsolutions.github.io/siesta/
MIT License
2.19k stars 159 forks source link

Memory Management review #21

Closed pcantrell closed 8 years ago

pcantrell commented 8 years ago

Swift’s open sourcing has revealed interesting details about how weak references work internally:

https://www.mikeash.com/pyblog/friday-qa-2015-12-11-swift-weak-references.html

The section of note:

Weak references to an object will cause that object's memory to remain allocated even after there are no strong references to it, until all weak references are either loaded or discarded. This temporarily increases memory usage. Note that the effect is small, because while the target object's memory remains allocated, it's only the memory for the instance itself. All external resources (including storage for Array or Dictionary properties) are freed when the last strong reference goes away. A weak reference can cause a single instance to stay allocated, but not a whole tree of objects.

Review Siesta’s memory management policies in light of this. Relevant sections of code:

https://github.com/bustoutsolutions/siesta/blob/master/Source/Support/ARC%2BSiesta.swift https://github.com/bustoutsolutions/siesta/blob/master/Source/Support/WeakCache.swift#L51-L52 https://github.com/bustoutsolutions/siesta/blob/master/Source/ResourceObserver.swift#L297-L303

pcantrell commented 8 years ago

I think we’re in the clear here. As far as I can trace through, in a low memory event, the cleanup touches every weak reference that might have been zombified.

We can reopen the inquiry if we observe unexplained memory leakage in the wild.