bash-oop icon indicating copy to clipboard operation
bash-oop copied to clipboard

Objects created in subshells are not destructed

Open doak opened this issue 5 years ago • 0 comments

Destructors are lost if a subshell is spawned like this:

(
    Empty will_be_never_destructed
)

This is because the instance is created in the subshell but the trap is only executed by the parent. Do you have any idea to solve this? Setting the trap inside every instance creation does not solve this, since this would destroy the objects of parent shell twice because the mangled instance variables are copied to the subshell (even if not exported). I am testing with Bash v4.4.23.

By the way: Very cool implementation -- under 300 lines of code :)

doak avatar Dec 31 '18 00:12 doak