我需要做這樣的事情:使用PInvoke中的結構後,是否需要釋放內存?
TEXTMETRIC tm;
bool isTrueType = false;
if (NativeMethods.GetTextMetrics(hDC, out tm))
{
isTrueType = ((PitchAndFamily)tm.tmPitchAndFamily & PitchAndFamily.TMPF_TRUETYPE) == PitchAndFamily.TMPF_TRUETYPE;
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf<TEXTMETRIC>(tm));
Marshal.StructureToPtr<TEXTMETRIC>(tm, ptr, true);
Marshal.FreeHGlobal(ptr);
}
或將分配memeory被自動清理一次函數退出? 我想(從我讀過的)這是後者,但我不確定!
任何澄清讚賞!