Native的C++代碼來說,內存洩露就是New的對象沒有delete,資源洩露就是申請的系統資源沒有釋放(最常見的就是DC的句柄),
在程序退出是仍然佔用系統內存和資源。
對Managed Code C# 來說,內存洩露就是指有些對象被過於長時間的引用,從而導致整個程序的內存佔用過多,
當然關閉程序以後,這些內存還是可以被GC回收的。
我們 可以通過.Net Memory Validator和.NET Memory Profiler 3.1來跟蹤內存的使用情況,從而分析內存洩露。
兩個例子:
1. 比如一個全局的ArrayList裡邊New了很多的對象,這個ArrayList只在一個函數裡邊使用,
那麼在這個函數調用結束的時候,就必須給 ArrayList賦值為null。
否則這個全集的ArrayList只能等到程序結束的時候才能被釋放,
在這個期間因為ArrayList的引用,導致 ArrayList裡邊的對象不能被釋放回收。
2. 比如一個SolidBrush對對象,沒有包括在using語句中,那個這個對象就不會自動被調用despose接口,導致內存洩露。
Here you can download the full version of .NET Memory Profiler. When starting the profiler you will be prompted to enter a registration key. The registration key is obtained by buying .NET Memory Profiler. If no key is entered the program will run as a time limited evaluation version of the professional edition.
Download .NET Memory Profiler 4.0
(MemProfilerInstaller4_0_118.exe)
(28,155 KB, version 4.0.118, November 16, 2011)
Read the release notes for information about additions and changes to .NET Memory Profiler.
To install the software, run MemProfilerInstaller4_0_118.exe. .NET Framework (v2.0, v3.0, v3.5, or v4.0) must be installed on the system before installing the memory profiler.
NOTE! .NET Memory Profiler can be run on Windows XP, Windows Vista, Windows 7, or Windows Server 2003/2008. Windows 98/Me/NT/2000 is not supported.
.NET Memory Profiler 4.0 cannot be used to profile .NET 1.x applications. For .NET Framework 1.x support, download version 3.1 or 3.5.
If you need to install .NET Memory Profiler using MSI-files, you can download them from here:
Download .NET Memory Profiler 4.0 for 32-bit Windows
(MemProfilerInstaller4_0_118-32bit.msi)
(25,680 KB, version 4.0.118, November 16, 2011)
Download .NET Memory Profiler 4.0 for 64-bit Windows
(MemProfilerInstaller4_0_118-64bit.msi)
(27,256 KB, version 4.0.118, November 16, 2011)
Registered users of .NET Memory Profiler can download the previous versions:
.NET Memory Profiler 3.0 (64-bit)
.NET Memory Profiler 3.1 (64-bit)
.NET Memory Profiler 3.5 (64-bit)
KeyGenGuru.Com - serial numbers, keygen, cracks, serial key generators - SciTech .NET Memory Profiler 3.1.319
Name: Buddy Knox s/n: 2117-6749-0386-2380-6667