Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cross reference objects
Message
 
 
To
24/10/2001 09:56:45
Marco Beuk
Innovero Software Solutions
The Hague, Netherlands
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00572577
Message ID:
00572589
Views:
39
This message has been marked as the solution to the initial question of the thread.
The memory is increasing because the objects are never getting released. They continue to sit in memory. Setting the variables to NULL doesn't do anything because object references still exist and since they do, the objects are never destroyed. Add the lines in BOLD below and that should take care of it.

The reason is that when you AddProperty, the child object isn't aware of anything that happens to the "Parent" object. When the parent is released/destroyed, the child object still exists in memory; however, you have lost your reference to it. Because each object is a child of the other and they don't know when the parent "goes ways" they remain, creating your "memory leak".

HTH.

>We had an ever growing DLL (could have been an exe too). After analyzing the code for many hours we discovered the cause of the problem:
>Within a method of object A we did a createobject to object B and passed A (this). In the init of object B we store the passed object in a property.
>
>Try the following for example:
>
>FOR nTel = 1 TO 1000
>  x = CreateObject( 'textbox' )
>  y = CreateObject( 'textbox' )
>
>  x.AddProperty( 'test', y )
>  y.AddProperty( 'test', x )
>
<b>   x.Test = null
   y.Test = null</b>
>  x = null
>  y = null
>ENDFOR
>MESSAGEBOX('Watch the memory usage in the taskmanager')
>
>
>While executing this code watch the memory usage in the taskmanager. It grows up to 18 MB!!
>IF you remove the link y.AddProperty( 'test', x ) not only the memory usage is growing but performance differs 20 times or more!
>
>Our solutions will be the usage of an intermediair object z:
>z point to x, z points to y and y points to z so that we can refer from y to x with y.z.x
>
>Marco.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform