-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should destroyObject
also replace .destroy()
?
#12266
Comments
destroyObject
also replace .destroy()
destroyObject
also replace .destroy()
?
I just stumbled over this issue. And I agree that some of this could be reviewed, in terms of convenience or the potential for error. Some of the complexity here cannot be avoided: The lifecycle management of GL-objects has to be explicit. And some ideas behind the In general, I agree that it would be nice if the pattern of But this is usually not how the This is related to why I think that Owner.prototype.destroy = function () {
// 'Recursively' destroy all owned things that
// can be destroyed
this._owned.destroy();
return destroyObject(this);
} This cannot be done in for (const key in object) {
if (typeof object[key] === "function") {
// If the property is destroyable, then call "destroyObject" on this property as well:
if (key === "destroy") {
destroyObject(object[key]);
} else {
object[key] = throwOnDestroyed;
}
}
} (This is a sketch here, but might actually work...) The point about the usage of And the intended usage of
I've seen snippets like
and knowing which properties even could be But some of this could be automated, similar to the draft above, with
One concern would be that people could add a function called |
If this is the only alternative we can come up with then I don't think it should happen. As you pointed out this opens up a lot of unknowns about properties that may or may not exist. Also the potential to call destroy on something that's in a property but not considered fully "owned" by the object being destroyed.
Replacing the |
Yes, the side-effects are hard to predict here, and that approach would require a concept of "ownership" that is much more strict than what is even possible in JS.
I think I misunderstood one detail there. Generally speaking, calling "destroy" on a destroyed object should be safe and a no-op. In other languages, this is solved with some final void destroy() {
if (isDestroyed()) return;
reallyDestroy(); // To be implemented by subclasses
} But given that it's possible to juggle around |
While reviewing #12129 I finally noticed the
if !isDestoryed() > .destroy()
pattern and it felt very odd to me.My comment:
Looking at the
destroyObject
function I see we delete all the properties and replace the.isDestroyed
function with a function that only returns true.cesium/packages/engine/Source/Core/destroyObject.js
Line 53 in 192ab06
I think a potentially easy path forward to streamline this pattern and fit the way I expected it to work would be to also (or maybe instead of) replace the
.destroy()
function with a noop() => {}
.This would allow us to rewrite that original example as just one line and not have to care about checking first. The responsibility is with the original object even though it's all been deleted by
destoryObject
The text was updated successfully, but these errors were encountered: