You may be aware that garbage collection is the process by which unused memory is reclaimed. There are various ways that memory can become unused, for example, it was allocated in a let statement and this block of code has been executed and exited, or as you state, by effectively removing references to the memory. Once all references to a chunk of memory have been removed, it is liable for garbage collection. This process occurs every so often, but can be initiated by the user also, using the gc() function. See the following section in the SKILL Language User Guide in SourceLink: "Memory Management (Garbage Collection)"
I would recommend using an encapsulation technique when writing your PCell code, so that the code that does all of the work is encapsulated in a procedure which can be debugged outside of the PCell development, and also potentially re-used by other PCells. Something like the following:
list( ddGetObj("libName") "cellName" "layout")
( paramA 1.0 )
( paramB 2.0 )
myPCellTopFunction( pcCellView paramA paramB )
Hopefully the above information and pointers will help you.