richtelieu88
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER