Author Topic: Script disposal question  (Read 40 times)

lskovlun and 1 Guest are viewing this topic.

Offline doomlazer

Script disposal question
« on: Today at 12:54:02 PM »
It seems that if you dispose a script in SCI, you can still check its properties afterward and get the expected values from before disposal. It's not until room change that it appears to really flush the script entirely. This feels a bit confusing because if it's not freeing up the heap before room change, what's the point?

Is it just marked disposed and still accessible until overwritten by new objects? It would be helpful to understand how that's working under the hood. TY



Offline Kawa

Re: Script disposal question
« Reply #1 on: Today at 01:10:45 PM »
You're right in that the data is still left there to be reused. But use-after-free is a common source of issues in many languages and you should never rely on it.

Offline doomlazer

Re: Script disposal question
« Reply #2 on: Today at 01:16:01 PM »
But use-after-free is a common source of issues in many languages and you should never rely on it.

I wouldn't dare, but to confirm, it's just sitting around waiting to be overwritten after dispose is called, right? Would delete: do anything different here or at least clear the pointer to the disposed object so it's no longer accessible? Just curious

Offline Kawa

Re: Script disposal question
« Reply #3 on: Today at 01:22:25 PM »
It's just sitting there waiting to be overwritten. If you have a pointer to an object and delete the object, that does not change the pointer's value. It will be stale and unsafe to use.

Offline doomlazer

Re: Script disposal question
« Reply #4 on: Today at 02:03:12 PM »
So my question would still be does (self dispose: delete:) do anything different than (self dispose:) ?

Offline Kawa

Re: Script disposal question
« Reply #5 on: Today at 03:13:14 PM »
That depends entirely on the implementation of the two.

Ultimately, Object::dispose calls the (DisposeClone self) kernel call, which only releases the memory block used by the object without wiping it.

What delete does depends on what's being deleted -- Collection::delete ends up doing the same thing to the indicated items, while for Views and everything derived from them like Actors and Props, it manages removal from the cast list and disposing of the underbits (little screenshot of what's behind them).

In both cases, the data is still there. And I still highly recommend not trusting it to remain there.

Offline doomlazer

Re: Script disposal question
« Reply #6 on: Today at 03:25:10 PM »
Great, thank you for the information!

Online lskovlun

Re: Script disposal question
« Reply #7 on: Today at 04:49:21 PM »
It also depends on whether the script is a clone or not. It is not the usual case - scripts are usually instances for which DisposeClone does nothing. But you can clone script objects in order to use them on several actors, for example. And then there's DisposeScript, which is another thing entirely (but which is also allowed to leave bits and pieces behind in a readable state).

(script dispose:) also has the side effect of resetting some properties, so that the script can be reused later.


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.028 seconds with 22 queries.