Last active
December 13, 2015 03:04
-
-
Save nuitsjp/b3b023ccb6974c2e8898 to your computer and use it in GitHub Desktop.
やりがちなアンマネージドメモリのリークと対処方法 ref: http://qiita.com/Nuits/items/9ce6a205a50bf8e3dbeb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IntPtr srcIntPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(length); | |
try | |
{ | |
// ここに処理を記載する | |
} | |
finally | |
{ | |
System.Runtime.InteropServices.Marshal.FreeCoTaskMem(srcIntPtr); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IntPtr srcIntPtr = IntPtr.Zero; | |
try | |
{ | |
srcIntPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(length); | |
// ここに処理を記載する | |
} | |
finally | |
{ | |
if(srcIntPtr != IntPtr.Zero) | |
{ | |
System.Runtime.InteropServices.Marshal.FreeCoTaskMem(srcIntPtr); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions(); | |
try { } | |
finally | |
{ | |
IntPtr srcIntPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(length); | |
try | |
{ | |
// ここに処理を記載する | |
} | |
finally | |
{ | |
System.Runtime.InteropServices.Marshal.FreeCoTaskMem(srcIntPtr); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IntPtr srcIntPtr = IntPtr.Zero; | |
try | |
{ | |
System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions(); | |
try { } | |
finally | |
{ | |
srcIntPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(length); | |
} | |
// ここに処理を記載する | |
} | |
finally | |
{ | |
if(srcIntPtr != IntPtr.Zero) | |
{ | |
System.Runtime.InteropServices.Marshal.FreeCoTaskMem(srcIntPtr); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment