[LLVMdev] How to avoid memory leaks

Jeffrey Yasskin jyasskin at google.com
Tue Mar 23 09:00:44 PDT 2010


On Tue, Mar 23, 2010 at 7:53 AM, Anders Johnsen <anders at skabet.net> wrote:
> I think you need to call "llvm::Function::deleteBody() first"

Nope, ~Function calls dropAllReferences() the same as deleteBody() does.

> On Tue, Mar 23, 2010 at 15:49, Reid Kleckner <rnk at mit.edu> wrote:
>> On Tue, Mar 23, 2010 at 7:04 AM, Gabi <bugspynet at gmail.com> wrote:
>>> Hi
>>> I get huge memory leaks using LLVM IRBuilder (trunk version)
>>>
>>> Basically I recreate a function over and over again, and pretty sure
>>> that my code doesn't cause the leak
>>> while(true)
>>> {
>>>  Function *fn = module->getFunction(name);
>>>    if (fn)
>>>       fn->eraseFromParent();
>>
>> Err, shouldn't you delete fn here?  I'm pretty sure that this just
>> removes the function from the module.
>
> Doxygen says that:
> "eraseFromParent - This method unlinks 'this' from the containing
> module and deletes it."
>
> so it should be fine just calling erase.
>
>>
>>>    fn =  cast<Function>(module->getOrInsertFunction(name, fnType));
>>>    fillFunction(fn); //Fill function with some blocks and instructions..
>>> }
>>
>> Reid
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>
> - Anders
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>




More information about the llvm-dev mailing list