Re: What is the reference count for memory
- Posted by mattlewis (admin) Aug 23, 2009
- 904 views
In the memory allocation routines there is an optional parameter 'cleanup'.
If this is set the memory is released when a reference count reaches zero.
How is the reference count increased and decreased?
Would the reference count reach zero when the allocated memory is used as a parameter to a function or procedure and the call is completed?
The following code is a Windows XP example.
No. The reference count of the variable is decremented when the program leaves the code block that contains the variable. The block could be the routine in which it is defined, or the if/while/for/loop block in which it is defined. The reference count is also decremented when you assign something else to that variable. Of course, if you assign the value of that variable to another variable, then the reference count is incremented.
Matt