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

Posted on 2005-04-06
Last Modified: 2010-04-23
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

Question by:rrbecker
    LVL 69

    Expert Comment

    by:Éric Moreau
    Structures are value type. As soon as the structure gets out of scope, it is removed from the memory (without the GC to run).
    LVL 2

    Author Comment

    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???

    LVL 6

    Accepted Solution

    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
    LVL 2

    Author Comment

    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,


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    I'm currently working for a company where I have to upgrade over 50 VB6 programs to VB.NET 2008.  So far I'm about half way through, and I've learned quite a few tricks that drastically improve the performance of VB.NET apps. Because there are a…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now