I have been tracking down a bug in my code for a couple of days and finally realized that it seems the memory management doesn't pay any attention to the existence of Local references to information.
For example, I'd created a Local TPixmap variable in a main piece of code. Then I called a Method which loaded an image into a TPixmap and stored the handle to the pixmap in a Field variable as part of the type. Since that Field variable is permanent, it kept the reference to the pixmap. If, within the method, I then make that Field=Null, and do a flushmem, then my Local reference to that pixmap outside of the method is now also Null, even if I was wanting to still use it.
The whole problem was then fixed by changing the local into a Global, because then it seems like the memory manager `sees` that there is a second reference to the object and doesn't destroy it with flushmem. Things then behaved as I expected them to.
So, not saying this is a bug, just something to bear in mind, a lesson learned. If you want to keep your object references, you probably have to put them in non-Local variables, or at least know that doing a flushmem will also eliminate any local references if those are the only ones left.
Does this sound about accurate? Seems to be the case.
For example, I'd created a Local TPixmap variable in a main piece of code. Then I called a Method which loaded an image into a TPixmap and stored the handle to the pixmap in a Field variable as part of the type. Since that Field variable is permanent, it kept the reference to the pixmap. If, within the method, I then make that Field=Null, and do a flushmem, then my Local reference to that pixmap outside of the method is now also Null, even if I was wanting to still use it.
The whole problem was then fixed by changing the local into a Global, because then it seems like the memory manager `sees` that there is a second reference to the object and doesn't destroy it with flushmem. Things then behaved as I expected them to.
So, not saying this is a bug, just something to bear in mind, a lesson learned. If you want to keep your object references, you probably have to put them in non-Local variables, or at least know that doing a flushmem will also eliminate any local references if those are the only ones left.
Does this sound about accurate? Seems to be the case.