Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Freeing up a linked list

Status
Not open for further replies.

patljones

Programmer
Oct 4, 2001
6
GB
I've set up a linked list of Class Modules and I'm trying to free them up but it doesn't seem to be working. The watch shows that currfield is pointing to the right thing but its still in the chain after I set currfield to Nothing.

Do While Not currfield Is Nothing
Set nextfield = currfield.pnext
Set currfield = Nothing
Set currfield = nextfield
Loop

Do I need to set it up as a doubly linked-list and work the other way down the list or if I just set the root node to Nothing is VB intelligent enough to free up all the linked nodes.
 
I don't see anything wrong with your code. But you might try setting the pNext field to nothing like this:
Code:
While Not CurrField Is Nothing
   Set NextField = CurrField.pNext
   Set CurrField.pNext = Nothing
   Set CurrField = Nothing  ' <-- not strictly required
   Set CurrField = NextField
Wend

This will be OK since you've saved off a copy in NextField, and will ensure that CurrField should free up.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top