Local variable lifetime

BlitzMax Forums/BlitzMax Programming/Local variable lifetime

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I have a function... OnPaint()

Which is required to create an instance of a Paint object, which is used to draw with.

C++ creates a local variable, so that when the OnPaint function is finished, the variable loses scope and is removed from the stack immediately.

When I create a local BlitzMax variable, it will last well beyond the scope of the function (in memory... Delete isn't called until GC decides to).
Having this around after the OnPaint causes issues on Windows.

I have worked a way around it, by making a call to my Paint object's Free() method, which frees the under-lying data, and removes the problem.

Without explicitly asking the GC to cleanup, I guess there is no way around the problem, is there?

I'm happy enough using Free(), if that's what it takes.