Article Preview
Buy Now
| Print: | |
| PDF: |
Object-Oriented Thinking
Article
Issue: 1.4 (February/March 2003)
Author: Charles Yeomans
Author Bio: Charles Yeomans is a software developer in Lexington, Kentucky
Article Description: No description available.
Article Length (in bytes): 4,748
Starting Page Number: 36
RBD Number: 1418
Resource File(s): None
Related Web Link(s):
http://developer.java.sun.com/developer/TechTips/2000/tt0124.html
Known Limitations: None
Excerpt of article text...
A fundamental task of any modern object-oriented language is that it handle memory management. REALbasic performs this task using a scheme called reference counting. For every object created, RB keeps a count of references to that object; when the count reaches 0, RB destroys the object and reclaims the memory used.
Reference counting has a notable weakness; it cannot reclaim circular structures. If one or more objects refer to each other, then their reference counts will never go to 0, and so their memory will never be reclaimed by RB. Here is perhaps the simplest possible example.
Sub LeakOneObject()
dim person as cPerson
person = new cPerson
person.Child = person
End Sub
Once this method finishes executing we have no way of referring to the object created in LeakOneObject, because the only references to it have gone out of scope. Because the object holds a reference to itself, the reference count will never go to zero, and so the object will never be destroyed and its memory is lost to the application.
...End of Excerpt. Please purchase the magazine to read the full article.
Article copyrighted by REALbasic Developer magazine. All rights reserved.
|







