Memory management by interfacing C/C++

Ferhat Kurtulmuş aferust at gmail.com
Sun Apr 28 23:10:24 UTC 2019


On Sunday, 28 April 2019 at 03:54:17 UTC, Paul Backus wrote:
> On Saturday, 27 April 2019 at 22:25:58 UTC, Ferhat Kurtulmuş 
> wrote:
>> Hi,
>>
>> I am wrapping some C++ code for my personal project (opencvd), 
>> and I am creating so many array pointers at cpp side and 
>> containing them in structs. I want to learn if I am leaking 
>> memory like crazy, although I am not facing crashes so far. Is 
>> GC of D handling things for me? Here is an example:
>>
>> [...]
>>
>> The question is now: what will happen to "int *cintv" which is 
>> allocated with new operator in cpp code? I have many code 
>> similar in the project, but I have not encounter any problem 
>> so far even in looped video processings. Is GC of D doing 
>> deallocation automagically?
>> https://github.com/aferust/opencvd
>
> D's GC only collects memory allocated with D's `new` operator. 
> Memory allocated by C++'s `new` operator must be freed by C++'s 
> `delete` operator.

You are right. I am rewriting the things using mallocs, and will 
use core.stdc.stdlib.free on d side. I am not sure if I can use 
core.stdc.stdlib.free to destroy arrays allocated with new op.


More information about the Digitalmars-d-learn mailing list