Closing banks
BlitzMax Forums/BlitzMax Programming/Closing banks
| ||
I have a method in a class I am writing that uses TBank and CreateBankStream to save data:Method SaveToDB(db:Int) Local Bank:TBank Local Stream:TStream Local Str:String Bank = CreateBank(256) Stream = CreateBankStream(Bank) ' WriteInt, WriteString, etc used to write data to the Stream SeekStream(Stream, 0) Str = ReadString(Stream, StreamSize(Stream)) ' Str is stored to the DB here CloseStream(Stream) EndMethod I have a few questions on my methodology here: 1. Do I need to destroy the TBank object or will the GC get it? There is no CloseBank() command so I assume that it will be deleted once it goes out of scope at the end of the method. 2. Is there a better way to get a string or equivalent pointer from a bank or stream than "Str = ReadString(Stream, StreamSize(Stream))"? This is passed into a DLL call to store it in the database. |
| ||
1: bank=null, then let the garbage collector do its thing.. btw, for garbage 'n things I tend to put thee GCCollected() value on screen in some corner, then you know exactly when something's leaking away. |
| ||
1: If the bank is created locally, you don't even need to do that. bank=null then let the garbage collector do its thing.. |
| ||
Behold: If you send Self as 'extra' event (created locally in the class) to some hooked function, then bmax seems to be making a copy of it. If you don't NULL this created event you'll end up with a memleak the size of the Self object you were sending, each time you perform this sending of Self. Took me the best part of a day to find out about this :P |
| ||
The extent of my use for the TBank variable is the CreateBankStream call, so thus far I believe it will be freed correctly on leaving scope. btw, for garbage 'n things I tend to put thee GCCollected() value on screen in some corner, then you know exactly when something's leaking away. Looks like there is a GCCollect() function, but it says it actually runs the garbage collector. So that leads to a couple more questions: does the GC actually run without calling this? I hope so. Also, would calling this frequently cause problems? |
| ||
arf, yes, ofcourse I meant: GCMemAlloced() |
| ||
This is sort of OT but I really like BMax's balance of features. I mean, on the surface it doesn't seem like there's a GC in there--but there is. I'm surprised every day at how good this stuff is. |