Databuffers and the GC

Monkey Forums/Monkey Programming/Databuffers and the GC

Sicilica(Posted 2015) [#1]
So, I'm slightly confused on this.

A little while back I was working on a bunch of opengl code in monkey, and there was a point where I realized I was leaking a bunch of memory. This stemmed from a bug where I was accidentally creating a new databuffer to use for a texturebuffer on every frame (haha, whoops, that was only supposed to get called if resolution changes...), but I hadn't even noticed the Discard() method before.

My question is this: does every DataBuffer need to have it's contents Discard'd at it's end of life, or did I only run into that problem as a side effect of using it to fill a void* or whatever argument in the opengl module? Because, since I tend to trust the GC and not think about my pointers, it caught be pretty off guard (although since obv the actual opengl code isn't running inside the GC I should have expected this). I guess it'd be nice if this was better documented so people weren't surprised by it (or worse, never noticed!).


marksibly(Posted 2015) [#2]
DataBuffer should eventually release their memory - the keyword here being 'eventually'.

Since 'finalizers' (ie: when databuffers actually get around to actually releasing their memory) may not run until 'sometime in the future', and since databuffers may be holding onto considerable amounts of memory, I strongly recommend using Discard, the way you should with Images etc.