Delete the reference MEMORY
So as asked, I am not talking about KILL - KILL as stated in the docs:
This command removes the variable. If there are no further references to the object, this command also removes the object from memory,
I want to remove the object from memory even if it is still referenced in memory - I understand that cache is not a low-level programming language, But i was hoping there is a way.
Notice that have a RegisteredObject and it is a single reference, It is different than the UnSwizzles suggested in other posts.
Product version: Caché 2016.1
I'm not sure wha you want to achive, so I ask a puzzling question: do you want to create dungling object? "I want to remove the object from memory even if it is still referenced in memory", as I understand, would free the memory used by an object but let the object referenc(es) intact, so the reference now would point into nirvana. Is that what you want to do? Why? Can you a little bit elaborate, what is your target or the background respectively?
So basically it's used as a last resort because in some places, And although i understand in theory i could add a property and i would turn it off if i want the reference "killed" and just check that property, This is one of the options that came up.
What you intend to do is completely against the concept of Caché and IRIS
And against most concepts that made the core products strong.
It's best compared to take out all vocals from written language.
The logic lies in the design of the system
So you probably should change the logic that requires such sick actions.
> I want to remove the object from memory even if it is still referenced in memory
That makes no sense and it is not possible, it would invalidate every other variable or object property that references it.
But why do you want to do this?
The logic lies in the design of the system i am working on.
Simply put, i would kill a reference to an object only in case i would WANT to aggressively kick any place that tries using this object after i killed it.
It is done only on very specific occasion.
Just for the case, you are lost in the working memory space and desperately searching the spot(s) in your programm where a specific object is once again referenced, here a small handy method which could help you
/// find all variables which contain a given object(reference) /// /// I: the OREF you looking for /// /// O: "" if the spool-device can't be opened /// [] if no variables contain the given OREF /// [var1, var2, ... varN] an array of variable names (incl. subscripted and orefs) /// ClassMethod FindObject(obj) { set res=[] if $d(%)#10,%=obj do res.%Push("%") new % set %=obj kill obj lock +^SPOOL("nextID") // adapt this lines open 2:($o(^SPOOL(""),-1)+1):1 // to your method of lock -^SPOOL("nextID") // creating new spool IDs if $t { use 2 set spl=$zb do $system.OBJ.ShowReferences(.%,1) for i=1:1:$za-1 { set x=$p($zstrip(^SPOOL(spl,i),"<=>w",$c(13,10))," ",3) do:x]"%.~" res.%Push(x) } close 2 kill ^SPOOL(spl) } else { set res="" } quit res }
Example
USER>kill USER>set pers=##class(DC.Person).%OpenId(1) USER>set temp=pers, zz(3)=temp USER>write ##class(DC.Help).FindObject(pers).%ToJSON() ["pers","temp","zz(3)"]