Imagine that you call from a language with GC repetitively a function from another language (e.g., Fortran 95). The Fortran function leaves something allocated in the memory between calls which might be seen from the caller language as unreferenced rubbish.
Could GC from the caller language access the memory allocated in Fortran and consider it as rubbish and free it?
I guess that it won't happen. The memory allocated by the Fortran function should have its own memory management separated from the memory managed by GC, however, I would be happy if anyone could confirm that.
Why do I need it? (if anyone is interested)
As described above, I need to write a function in F95 which allocates its own memory, is called several times and it needs to keep the reference to the allocated memory between calls. The problem is that Fortran pointers are incompatibile with the outside world so I can't just pass something as 'void *' from Fortran. Therefore the Fortran function would store the pointer not as a pointer but would cast it (for example) as an integer array for the outside world. However, if GC could anyhow interfere memory from Fortran, it might not understand that the reference is kept in the integer array and might want to free the memory allocated in Fortran, which would be bad.
No, unless the language explicitely integrated with the host langauge (using the garbage collector). In .NET... a C++ application can use C++/CLI to allocate .NET objects and return those - and those naturally are garbage collected. I do that in a number of projects.
But a pure C++ object... the garbage colelctor knows nothing about and does not know how to handle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With