How do you deal with resource dependencies in combination with custom destructors? #4074
Unanswered
codecnotsupported
asked this question in
Q&A
Replies: 1 comment 1 reply
-
The ideal solution is not to have those dependencies at all or keep both in the same resource and properly implement |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Suppose you have, resource A and B.
B is derived from A. / Created with resources from A. (Not really relevant)
B must be destroyed before A.
B requires a custom destructor to properly de-allocate itself, and requires access to resource A to do so.
The only way I can make this work (that I can think of) by having a reference of resource A inside of resource B.
But the borrow checker makes this a tad bit difficult, because (as far as I understand, the lifetime of a resource is dynamic).
Is the resource drop order the inverse of the initialization order, because, if that is not then there is the issue that A might be dropped before B.
Beta Was this translation helpful? Give feedback.
All reactions