Fix refcounting/deallocation mechanism for stack allocated objects

This is done by
 * introducing a flag denoting ojects allocated on the heap
 * Setting that flag in each existing derived "class".