Release, Remove, Null, RemoveLink & ListRemove ?
BlitzMax Forums/BlitzMax Beginners Area/Release, Remove, Null, RemoveLink & ListRemove ?
| ||
What are they all for, and what are the relationships between them? I notice that the samples use different methods to kill user type objects: Release, Remove, p=Null. Do they all actually free the object (once a Flushmem is called)? The docs (and samples) are very unclear in this area. Are Remove and RemoveLink related? |
| ||
i've made a little test. Here it is:Local mylist:tlist = CreateList() Type mytype Method yo() Print "i'm still here" End Method End Type m:mytype = New mytype ListAddLast mylist, m Print "items in list: " + CountList( mylist ) mylist.remove( m ) m.yo Print "list Remove method called. Items in list: " + CountList( mylist ) FlushMem m.yo Print "Flushmem called. Items in list: " + CountList( mylist ) WaitKey() End After I call the mylist.remove() method, I still can access the type after calling Flushmem. What is going on? The hi-toro RockOut example states that calling mylist.remove() should also DELETE the type in addition to removing it from the list. Maybe it's an early example, but it IS released with BMax... |
| ||
I don't see the weirdness. As a type can be a part of multiple lists at once it seems logical the type itself isn't deleted if it's removed from the list. 'Release m' will remove the type itself. |
| ||
I think the confusion comes from an example in the samples folder "hitoro\Rockout.bmx" that claims that Remove() does release the object itself. Look for yourself. :) |
| ||
Just an aside. Types themselve are never accessed, only instances of Types (commonly called objects) are. Important to get this right, especially as there are alot of newbie OO programmers getting into BlitzMax and this could just confuse them more. |
| ||
Just found these: http://www.blitzmax.com/Community/posts.php?topic=41821 http://www.blitzbasic.com/Community/posts.php?topic=42016 |
| ||
After I call the mylist.remove() method, I still can access the type after calling Flushmem. Yes. But you can't access the one in the list. Try this:Local mylist:tlist = CreateList() Type mytype Method yo() Print "i'm still here" End Method End Type mylist.addLast(New mytype) myType(myList.First()).yo() Print "items in list: " + CountList( mylist ) mylist.removeFirst myType(myList.First()).yo() Print "list Remove method called. Items in list: " + CountList( mylist ) FlushMem Print "Flushmem called. Items in list: " + CountList( mylist ) EndSee the Unhandled Memory Exception? That's because the type is gone. In your example, the type still exists, because there's still a reference to it (m). |
| ||
OK, this is starting to make sense to me now. (I wish the docs explained this more in detail) The posts Beaker found explain a lot as well. I hope Beaker has found this interesting as well. Thanks all! |
| ||
ust an aside. Types themselve are never accessed, only instances of Types (commonly called objects) are. That's actually incorrect. A "function" or "global" within a type can be accessed without having an instanced object. |
| ||
Am I being thick again? Because the documentation seems decidedly thin on info on this stuff.. for example: After I call the mylist.remove() method, I still can access the type after calling Flushmem. where are the standard methods for an object described in the docs? It seems at the moment the only real solution is to trawl through the module source, which is hardly ideal.. |
| ||
for example: It's a bad example, as it's a false positive. where are the standard methods for an object described in the docs? I don't think there is one unfortunately. It seems as-if the docs are targeted more at traditional procedural programmers... It seems at the moment the only real solution is to trawl through the module source, which is hardly ideal.. True. But it's very effective. :o> |
| ||
It seems as-if the docs are targeted more at traditional procedural programmers... Which in my limited experience using Max, procedural programmming should be phased out anyway. =] |