Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Deallocate not working for me
#1
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.
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Reply
#2
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.
Reply
#3
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:
Reply
#4
Oh, so it is working. Thanks.
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Reply
#5
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..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)