Link to home
Start Free TrialLog in
Avatar of richtelieu88
richtelieu88Flag for United States of America

asked on

Release Dynamically Allocated Memory in C#

I need to know the correct way of releasing dynamically allocated memory on function exit in C#.

Let's say I have a function:

Private void SomeFunction()
{
      IntPtr[] h = new IntPtr[100];
       . . . .
      //Do Something
       . . . .

      //Is this the correct way?
      h = new IntPtr[0];
      h = null;
}

Is this proper?  Will this release the memory to the system?

If not, how should I do this?

Is an ArrayList the only way to ensure the memory is released?

If so, how do you release memory in an ArrayList when finished?  Or does this happen on its own?

Thanks in advance.
SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of richtelieu88

ASKER

Thank you both.