How do I FREE up (delete) a structure in VB.NET

Greetings All,

I think I know the answer to this question but I will ask it for assurance.

The structure that I want to Free up is a Structure that contains and Array of other structures.

I load these structures at 'Load' time and until recently I have not wanted or needed to re-load the entire structure. But like a lot of other things, things change.

So what is the best way to Free up these structures??? I assume that I have to Free them from the 'Inside Out'....

Thanks in advance

Who is Participating?
TDSnetConnect With a Mentor Commented:
Hi RRBecker,

I'm not sure how you would test this but I believe that using:

MyStruct = Nothing

Will deallocate all memory usage associated with that particular declaration.


Jack Pick
Total Data Solutions
Éric MoreauSenior .Net ConsultantCommented:
Structures are value type. As soon as the structure gets out of scope, it is removed from the memory (without the GC to run).
rrbeckerAuthor Commented:
Hi emoreau,

I have it set up as a FRIEND and 'Globally' allocated. (I know, no Global in .NET) and Never goes out of scope....

Can I do something in the nature of: 'MyBigStructure = NOTHING' and be assured that all elements of the structure have been de-allocated, even the 'nested' structures???

rrbeckerAuthor Commented:
Hi TDSnet,

I wasn't sure it that would completely Free up All memory so I used a varaiation, I did the following:

       ' try to clear the current structure
        For GroupIndex = 1 To ButtonStruct.GroupCount
            ReDim ButtonStruct.GroupStructure(GroupIndex).ItemStructure(0)
        ReDim ButtonStruct.GroupStructure(0)
        ButtonStruct = Nothing
----------end snippet------------------------------------------------------------------

This seems to work ok but I haven't really had a chance to 'hammer' on it so I don't know if I'll run into problems later or not.

I had actually had this coded and running before I read you comment but I am going to accept you answer.

Thanks for taking the time to respond,

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.