Wednesday, March 30, 2011

Memory Management in REALbasic

Many times we see the question asked "when does REALbasic's garbage collector run" or something to this effect.

REAlbasic does NOT use a garbage collector like Java's VM does.(see Garbage collection on wikipedia) It uses reference counting (also mentioned on this same wikipedia page) and when the reference count drops to 0 the object is destroyed immediately. Not some time later but right then and there.

Note that this has certain implications. If you have circular references where one object has a reference to another and that object has a reference back to the first then the reference counts may never drop to zero. And, if for some reason you lose your original references to these objects then you can "leak" - or have objects that will never be destroyed but that you can no longer access or reference (well not easily at least).

There are some excellent resources that cover this in plain language and that give you some excellent tips on how to avoid common pitfalls.

The recent Atlanta conference had a session on Advanced Language features and Charles Yeomans covered this fairly well in his talk. I'd suggest that you find the video from this session when they are available on the ARBP site.

No comments: