I have large class which in many places I need to convert array to intPtr
IntPtr convertToIntPtr(Array input)
{
if (input != null)
{
int s = Marshal.SizeOf(input.GetValue(0).GetType()) * input.Length;
System.IntPtr p = Marshal.AllocHGlobal(s);
return p;
}
return new IntPtr();
}
I know each pointer can be freed using Marshal.FreeHGlobal(IntPtr)
.
my question is : - will garbagecollector free intptr once used - If no how can I free all of them in close or dispose of class , any event to use such that when intpntr no far used to be deleted