VB.net. variable memory de-allocation

Robert Tremblay 20 Reputation points
2023-01-31T20:43:20.12+00:00

Hi, do anyone knows how to free memory allocation of a matrix?

examples:

dim v(6000,5000) as single -> this creates a memory space of about 240Mb

now i want to release this memory space

I tried:

v=nothing or ERASE v

—> none works.

The debugger memory allocation manager still shows that this 240Mb still there.

Regards,

Robert

Developer technologies VB
0 comments No comments
{count} votes

Accepted answer
  1. Reza Aghaei 4,986 Reputation points MVP Volunteer Moderator
    2023-01-31T21:04:47.01+00:00

    Setting to null (Nothing in VB) will be enough, as it marks the memory space ready for garbage collection, and then garbage collector will collects the garbage automatically once it wakes up.

    If you want to force the garbage collection (not a best practice) you can call GC.Collect.

    Memory Release
    The garbage collector's optimizing engine determines the best time to perform a collection based on the allocations being made. When the garbage collector performs a collection, it releases the memory for objects that are no longer being used by the application. It determines which objects are no longer being used by examining the application's roots. An application's roots include static fields, local variables on a thread's stack, CPU registers, GC handles, and the finalize queue. Each root either refers to an object on the managed heap or is set to null. The garbage collector can ask the rest of the runtime for these roots. The garbage collector uses this list to create a graph that contains all the objects that are reachable from the roots.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.