Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Does dynamically allocating memory in a c-style dll and attempting to release it outside the dll amount to memory leak?
Posted

Yes. Memory leak will happen.
Because allocating memory in c-style will depend on the crt-heap, and the crt-heap is a global variable value that initialized at the beginning of module initialization.
So, if you allocate memory in A module, but free it in B module, it won't find the correct handle of heap, and memory leak happens.
 
Share this answer
 
A memory leak is when you loose track of allocating and releasing memory, so if you keep track of your allocations then you won't have a leak.
 
Share this answer
 
hi,
The basic rule of thumb is 'whoever allocated the memory, should free it too' . Its a helpful guideline which helps avoid trouble. Simply put, if memory was already allocated outside the dll and its handle is passed as input to the dll, then whichever entity did this memroy allocation,initially, should free it . And if the memory allocation was done ,say by a function inside the dll, then it is better to free it from within the dll itself. Anyways more googling should be helpful here.
Please take a look at this question[^]
 
Share this answer
 
Comments
Gbenbam 12-May-14 19:04pm    
Thanks that was a very informative discusssion you shared with me therer
No. It does not matter in which library the allocating code is located. I.e. while running the program, the memory model is independent of the way the code is linked.

On the other hand, for best practice, see the other solutions to your question.

Cheers
Andi
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900