I'm new to C++/CLI
, and would like a clarification on memory free up.
Imagine a scenario, where :
sampleServer srv = new sampleServer()
while(true)
{
ABC newObject = srv.getItem();
}
ABC^ sampleServer::getItem(){ return gcnew ABC(//LIST OF some parameters);}
Now here, unless a Dispose
is called by newObject
, because of a continuous stream of new objects which are being returned and not getting freed up, memory will continue to be allocated, but not released.
If I do not wish to call the DIspose
, the only other way is to have finalizers
taking care of the memory free up.
However, considering class sampleServer
, it does not have the object of class ABS as one of its members. It is still able to return a new instance of it, because of the to classes being in the same namespace.
So if I am considering class sampleServer
, what am I supposed to call the Finalizer
on?
And if the thought process is incorrect, how would I free up memory in the case given above?