Qbasicnews.com
Deallocate not working for me - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: Qbasic "like" compilers/interpreters (http://qbasicnews.com/newforum/forum-5.html)
+--- Forum: FB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-15.html)
+--- Thread: Deallocate not working for me (/thread-8914.html)



Deallocate not working for me - wallace - 02-20-2006

I'm sure that I'm just using it wrong:

Code:
Sub DestroyLinkedList(l as LinkedList)
   dim p as ListElement ptr
   dim c as ListElement ptr
   p = l.Head
    do while( p <> 0)
      c = p
        p = p->enext
      deallocate c 'remove list element
    loop
   deallocate @l 'remove last traces of list
End Sub

When I call my PrintLinkedList sub, it shows that nothing was removed.


Deallocate not working for me - RyanKelly - 02-21-2006

This doesn't mean that your memory has not been deallocated. All your pointers still point to the same places in memory, and nothing has been overwritten yet. Deallocating memory alerts your memory manager that it can use that memory in a future memory allocation.


Deallocate not working for me - Ryan - 02-21-2006

You can always set the pointers to NULL after deallocating as well. It's what I do, though I'm not sure that it's necessary. :wink:


Deallocate not working for me - wallace - 02-21-2006

Oh, so it is working. Thanks.


Deallocate not working for me - Z!re - 02-21-2006

Quote:You can always set the pointers to NULL after deallocating as well. It's what I do, though I'm not sure that it's necessary. :wink:
It's good practice, and helps avoid nasty bugs where you pass "dead" pointers.. If it's set to 0 most routines simply ignore it..