Biblioteca DLL / SO, ¿cómo se relaciona la memoria de la biblioteca con el proceso de llamada?

I was reading that all a process's memory is released by the OS when the process terminates (by any means) so negating the need to call every dtor in turn.

Now my question is how does the memory of a DLL or SO relate to clean up of alloc'd memory?

I ask because I will probably end up using a Java and/or C# to call into a C++ DLL with some static C style functions which will allocate the C++ objects on the heap. Sorry if I got carried away with the heap vs stack thread, I feel I have lost sight of the concept of _los_ heap (ie only one).

Any other potential pitfalls for memory leaks when using libraries?

preguntado el 28 de agosto de 11 a las 00:08

2 Respuestas

There is nothing for you to worry about. The operating system's loader takes care of this.

In general, shared libraries will be made visible to your process's address space via memory mapping (all done by the loader), and the OS keeps track of how many processes still need a given shared library. State data that is needed separately per process is typically handled by copy-on-write, so there's no danger that your crypto library might accidentally be using another process's key :-) In short, don't worry.

Editar. Perhaps you're wondering what happens if your library function calls malloc() and doesn't clean up. Well, the library's code becomes part of your process, so it is really your process that requests the memory, and so when your process terminates, the OS cleans up as usual.

Respondido 28 ago 11, 04:08

The library becomes part of the process when it is loaded. Regarding tidy up of memory, handles, resources etc., the system doesn't distinguish whether they were created in the executable image or the library.

Respondido 28 ago 11, 04:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.