Dispose methods Warning, Certainty 75, for DisposableFieldsShouldBeDisposed
Why I get this Warning, Certainty 75, for DisposableFieldsShouldBeDisposed?
publicstructVirtualMemoryPtr :IDisposable{
privatereadonlyIntPtr allocatedPointer;
privatereadonlyIntPtr processHandle;
privatereadonlyUIntPtr memorySize;
privatebool disposed;// wird von der Runtime auf false initialisiertpublic VirtualMemoryPtr(int memorySize)
{
processHandle =UnsafeNativeMethods.GetCurrentProcess();
this.memorySize = (UIntPtr)(uint)memorySize;
allocatedPointer =MemoryManager.AllocExecutionBlock((uint)memorySize, processHandle);
disposed =false;
}
...
...
publicvoid Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}privatevoid Dispose(bool disposing)
{
if(!disposed)
{
if(disposing)
{
// Release managed resources.
}
// Free the unmanaged resource ...
MemoryManager.VirtualFreeEx(ProcessHandle, AllocatedPointer, memorySize);
disposed =true;
}
}
}publicclassNativeAssembly :IDisposable
{
privateVirtualMemoryPtr nativeCodePtr;public NativeAssembly(byte[] code)
{
if(code ==null){thrownewArgumentNullException("code","NullArgument");}
nativeCodePtr =newVirtualMemoryPtr(code.Length);
Marshal.Copy(code, 0, nativeCodePtr, code.Length);
}
...
privatebool disposed;
~NativeAssembly()
{
Dispose(false);
}
{
Dispose(true);
GC.SuppressFinalize(this);
}
protectedvirtualvoid Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
// Release managed resources.
}
nativeCodePtr.Dispose();
disposed =true;
}
}
}
Is this kind of implementation wrong? What I'm doing wrong? Any idea?
thx
hahnl

