VB4 Objects & Memory Considerations

What happened was that I had objects pointing to other objects. To allow navigation back, I had also included pointers back to the ‘owner’ of the objects.

This last thing meant that the objects never got freed, because there was always something referencing them: the members were referenced by the parent, and the parents were referenced by the members. No matter if the caller set the pointer to the top-object in the hierarchy to nothing, the hierarchy remained in memory forever.

Another effect was, that the Class_Terminate event for the objects was never called, and that is were the objects’ contents are written to the data base.

The tip is: be careful with references between objects. If you have references like the ones described above, ensure that you have a method in the class that frees all cross-references. Otherwise objects never get freed, and their Class_Terminate event will never be called.

This may sound like a trivial something, but it took me quite some time to figure out why my application was never releasing its memory.

 

Tip Submitted By: Marjo van Diem


Discover more from dotNetTips.com

Subscribe to get the latest posts sent to your email.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.