IFSUPCUTILSize* size = NULL;
CoCreateInstance(CLSID_UTILSize, NULL, CLSCTX_INPROC_SERVER, IID_IFSUPCUTILSize, reinterpret_cast<void**>(&size));
if (size != NULL){
size->Release();
size = NULL;
}
delete size;
Do I need "delete size" in the code above?
If I include "delete size", will I have a memory leak because I did not use New?
Or is there a New inside the call to CoCreateInstance
.
I built this with VC++ 6.
A memory leak in Java is when objects you aren't using cannot be garbage collected because you still have a reference to them somewhere. An OutOfMemoryError is thrown when there is no memory left to allocate new objects.
Memory leaks don't result in physical or permanent damage. Since it's a software issue, it will slow down the applications or even your whole system. However, a program taking up a lot of RAM space doesn't always mean its memory is leaking somewhere. The program you're using may really need that much space.
Memory leakage occurs in C++ when programmers allocates memory by using new keyword and forgets to deallocate the memory by using delete() function or delete[] operator. One of the most memory leakage occurs in C++ by using wrong delete operator.
COM interfaces are reference counted. CoCreateInstance()
returns an interface pointer to a COM object whose reference count has already been incremented. Calling Release()
decrements the reference count. When the reference count falls to zero, the COM object frees itself automatically. DO NOT call delete
on a COM interface pointer! Always use Release()
only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With