M
Maxwell
Hello,
Newbie question here for disposing of unmanaged resources in MC++.NET.
I have a managed VS.NET 2003 MC++ wrapper class that wraps a unmanaged
C++ dll. What I am trying to figure out is what is the "best practice"
for disposing of pointers to unmanaged classes that you have newed in
your constructor in MC++
For a better description of what is the standard affair I have tried
looking online at:
http://msdn.microsoft.com/library/d...ml/vcmg_techniquesconstructorsdestructors.asp
but I would have to say its very lacking in detail or explanation. Does
anyone know of a better reference or can point me to for this?
My constructor looks something like this:
MClass::MClass()
{
pUnmanagedClass_ = new UnmanagedLib::UClass(); //unmanaged heap
pBridgeClass_ = new _UClassBridge(); //unmanaged heap
pUnmanagedClass_->RegisterUnmanagedCallBack(&(pBridgeClass_->UnmanagedBridgeCallback));
}
pUnanagedClass_ is a pointer to class in a unmanaged C++ DLL
pBridgeClass_ is a pointer to a __nogc class I created in MC++
Here is my destructor for this class:
MClass::~MClass()
{
pUnmanagedClass_->UnRegisterCallbacks();
pUnmanagedClass_->~UClass(); ///do I need this line
delete pUnmanagedClass_; //because it was newed
delete pBridgeClass_; //because it was newed
}
Since I newed the pointers I would guess that I would have to
explicitly call delete on them...is this the case? I also need to
ensure that destrutor gets called in the C++ DLL immediately
(pUnmanagedClass) so I added a line for this in the managed class
destructor...is this necessary or is it safe to assume it will get
called because the delete is called
Thanks
Newbie question here for disposing of unmanaged resources in MC++.NET.
I have a managed VS.NET 2003 MC++ wrapper class that wraps a unmanaged
C++ dll. What I am trying to figure out is what is the "best practice"
for disposing of pointers to unmanaged classes that you have newed in
your constructor in MC++
For a better description of what is the standard affair I have tried
looking online at:
http://msdn.microsoft.com/library/d...ml/vcmg_techniquesconstructorsdestructors.asp
but I would have to say its very lacking in detail or explanation. Does
anyone know of a better reference or can point me to for this?
My constructor looks something like this:
MClass::MClass()
{
pUnmanagedClass_ = new UnmanagedLib::UClass(); //unmanaged heap
pBridgeClass_ = new _UClassBridge(); //unmanaged heap
pUnmanagedClass_->RegisterUnmanagedCallBack(&(pBridgeClass_->UnmanagedBridgeCallback));
}
pUnanagedClass_ is a pointer to class in a unmanaged C++ DLL
pBridgeClass_ is a pointer to a __nogc class I created in MC++
Here is my destructor for this class:
MClass::~MClass()
{
pUnmanagedClass_->UnRegisterCallbacks();
pUnmanagedClass_->~UClass(); ///do I need this line
delete pUnmanagedClass_; //because it was newed
delete pBridgeClass_; //because it was newed
}
Since I newed the pointers I would guess that I would have to
explicitly call delete on them...is this the case? I also need to
ensure that destrutor gets called in the C++ DLL immediately
(pUnmanagedClass) so I added a line for this in the managed class
destructor...is this necessary or is it safe to assume it will get
called because the delete is called
Thanks