-
Notifications
You must be signed in to change notification settings - Fork 66
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
Behavior of types created in C++ when they go out of scope in Julia #403
Comments
I double-checked, and yes, in the case where a function returns an object by value like in your example, the wrapped object gets a finalizer and is owned by Julia. If a reference or pointer is returned then the default assumption is that the pointed-to object lifetime is managed by C++. |
Thank you very much - this makes a lot of sense 👍 If it is not too much to asked, it would be great if you could link the relevant code sections in here such that I (start to) understand better how libcxxwrap-julia and CxxWrap.jl work. Either way, feel free to close this issue any time. P.S.: Just to be sure: returning a |
The code where the by-value objects are returned is here: And indeed, it is the same for a |
Thanks for the confirmation! I've created #406 to document this for future reference. |
According to the README.md,
From this description it is not 100% clear to me what happens with types that are constructed by a library function on the C++ side that I do not control myself - will they also automatically have a finalizer attached?
For example, if on the C++ side I have something like
and I wrap this as
then technically calling
foo()
in Julia is neither here nor there:jlcxx::create
So far I have just assumed that CxxWrap.jl does The Right Thing and will automatically attach a finalizer to it, and thus once GC kicks in, the memory on the C++ side is freed as well. (Re-)reading the documentation again left me wondering if I am being overly optimistic about that.
The text was updated successfully, but these errors were encountered: