[Openmcl-devel] cocoa memory management best practices?
Raffael Cavallaro
raffaelcavallaro at mac.com
Fri Sep 24 07:08:57 PDT 2010
I think it would be useful to know the best way to deal with the life cycle of cocoa objects. Possibly the various situations can be enumerated and memory management best practices outlined for each.
Most importantly, please correct anything here that is wrong (i.e., likely to lead to a memory leak or outright crash), and please add any common situations that I've overlooked.
1. containing lisp class (i.e., not having ns:ns-object as its metaclass) with an objective-c slot.
- call ccl::terminate-when-unreachable on the containing lisp instance in its intitialize-instance method
- do necessary deallocation (#/release, etc.) of objective-c slots in a ccl:terminate method on the containing lisp class
2. containing Objetive-c class (with ns:ns-object as its metaclass) with a:
2a. lisp slot
- assume this lisp slot is taken care of by the gc?
2b. objective-c slot
option 1:
- call ccl::terminate-when-unreachable on the containing objective-c instance in its intitialize-instance method
- do necessary deallocation (#/release, etc.) of objective-c slots in a ccl:terminate method on the containing objective-c class
option 2:
- do necessary deallocation of objective-c slots in the containing objective-c class's #/dealloc method.
option 3 ?:
- for objective-c objects owned/managed by a custom window class, do necessary deallocation in the custom window's #/close method
3. Shared objective-c resources
- put the shared resource into a special var and let it live for the duration of the program (it's memory will be reclaimed when the app quits)
comments and corrections most welcome.
warmest regards,
Ralph
Raffael Cavallaro
raffaelcavallaro at me.com
More information about the Openmcl-devel
mailing list