Call to release and primary object destructor
Posted: 02 July 2021, 12:05
Hello,
I am wondering if I should delete any secondary object in the destructor of the primary object.
Example: In a Unit operation implementing COBIA, "Unit" is the primary unit operation class with a few basic secondary objects. In "Unit.h", I tried using the following destructor:
Where all of the above are pointers previously allocated their respective secondary objects in the constructor "Unit()".
While debugging I noticed a few calls to the destructor while calculating and ended up with an exception thrown for too many calls to release, so I removed all the delete statements and everything went well. I am curious to know why this happened. I thought the destructor would be called only when I delete the unit from my flowsheet.
Thanks in advance.
I am wondering if I should delete any secondary object in the destructor of the primary object.
Example: In a Unit operation implementing COBIA, "Unit" is the primary unit operation class with a few basic secondary objects. In "Unit.h", I tried using the following destructor:
Code: Select all
~Unit() {
delete(param);
delete(paramCollection);
delete(product);
delete(feed);
delete(portCollection);
}
While debugging I noticed a few calls to the destructor while calculating and ended up with an exception thrown for too many calls to release, so I removed all the delete statements and everything went well. I am curious to know why this happened. I thought the destructor would be called only when I delete the unit from my flowsheet.
Thanks in advance.