Completely Nulling A Type
BlitzMax Forums/BlitzMax Programming/Completely Nulling A Type
| ||
Hi. Does anyone has a procedure to totally Nulling a Type? What I mean is when a Type has Sub Types and when you null a Type you dont null its sub types.. Does anyone has a procedure which does that? Type Moshe Field Bubu:System_Stuff=new System_Stuff '... End Type Danny:Moshe= new Moshe like in this example above.. If i will do Danny=null it will only null danny but not Bubu.. Bubu will keep existing.. (right?) This, on the long term creates memory overloads So I must manually Null Bubu too. Im looking for a procedure which does that.. automatically Thanks How generally do you guys avoid/Test memory overloads? |
| ||
Bubu will keep existing.. (right?) No. As soon as "bubu" is not referenced by something anylonger, somewhen GC will catch it too. So if "bubu" was referenced by "Francine:Moshe" too, it would be staying in memory. If not, it would get cleared somewhen. If you want to handle things not referenced by the object, use the "Delete()" Method (override it, and do whatever you want to do as soon as the instance is removed/deleted). bye Ron |
| ||
OMG I didnt know there is a Delete Method up till now.. I need to check this.. Thank you.. |
| ||
If all you want to do is set fields to Null, then no, you don't need the Delete method. It already does that - to the extent that it's meaningful - for you. Delete is only useful for non-object resources like file handles, which BlitzMax doesn't know how to fully delete on its own, so you add additional information about cleaning them up in this method. It doesn't give you a way to delete BlitzMax-native objects. (There's an exception: in single-threaded mode, BRL's BlitzMax - not NG, or other languages - has a known bug to do with "circular references" which Delete can be useful in working around, but in practice if you just rely on solid single-ownership rules in your application design, this is highly unlikely to ever be a problem for you and not something you generally need to think about.) Anyway, setting a variable to Null does not delete the object referenced by that variable. That's not how this works. Set a variable to Null if and only if you want Null to be the value it contains; that's the only reason to do so. You cannot force objects to be deleted in BlitzMax by setting the value of fields or variables. Anyway, it's bad practice to try to manage object lifetimes yourself. Let the language handle it. It's better at it. |
| ||
Hi Yasha.. Let me explain you.. I have a command called LoadMap() then EraseMap() When I erase the map then reload it, the memory keeps increasing although it suppose to remain the same.. this means Im not deleting something.. All I know for deleting a type is doing = Null.. So I made a process to Null also its childes.. Yet, memory keeps increasing.. now im no the process of looking what causes it.. Null Is all I know :) Ill work on it.. Thanks for the explanation attempt, I partially understood what youre saying |