• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

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

rrbecker
0
rrbecker
Asked:
rrbecker
  • 2
1 Solution
 
É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).
0
 
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???

rrbecker
0
 
TDSnetCommented:
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.

Cheers,

Jack Pick
Total Data Solutions
0
 
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:

-------------snippet------------------------------------------------------------------
       ' try to clear the current structure
        For GroupIndex = 1 To ButtonStruct.GroupCount
            ReDim ButtonStruct.GroupStructure(GroupIndex).ItemStructure(0)
        Next
        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,

rrbecker
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now