How to totally remove an Object?

I looked at every Object method and, but I didn’t find how to remove/free/kill/destroy an Object completely, i.e. freeing the allocated memory and so on.

Does anybody know how one should do this ?

sclang is garbage collected, so an Object’s memory is free’d some time after nothing else refers to it. There is no manual control over this.

If you’re working with very large objects (e.g. large arrays), the best practice is to make sure that you’re only holding on them in one place, and then freeing them there when you are finished. As an example, the List class is a wrapper around a raw array - this sort-of guarantees that no one is referring to that Array other than the List. This means you can use List:clear and, assuming you didn’t cheat and pass around references to the underlying array), you will have freed the only reference to the array, which will cause it to eventually be cleaned up.

If you’re not working with very very large numbers of objects, very very large arrays, or code that runs for a very very long time, it’s really not worth worrying about this at all - it should just work.

Ok. Currently, I’m instantiating a View, that itself instantiate a custom Object style automatically. If I set a new style to this View, the previous style object becomes useless. Is it ok to left it untouched this way?

I’m not totally sure what you mean by a “custom Object style”, but in general what you’re describing is totally safe. If you overwrite an object in some slot with a new object, the old one will be cleaned up unless there’s someone else that’s referring to it elsewhere.

1 Like