[LLVMdev] How to avoid memory leaks
Anders Johnsen
anders at skabet.net
Tue Mar 23 07:53:00 PDT 2010
I think you need to call "llvm::Function::deleteBody() first"
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
More information about the llvm-dev
mailing list