[LLVMdev] LLVM and memory leaks

Morten Ofstad morten at hue.no
Mon Nov 15 01:24:46 PST 2004


Chris Lattner wrote:
>>It would also solve another problem -- We generate new shader code when
>>the user changes parameters, because the shader will be executed
>>millions of times it makes sense to recompile it with changed constants
>>to get maximum optimization. But if some of these parameters are floats,
>>and there is no way to destroy constants in LLVM we have a serious
>>memory leak situation here. Having the ability to flush all constants
>>and types and clear the TypeMaps/ValueMaps would be very useful to us.
> 
> If this is a serious issue, it would be straight-forward to add a global
> function to flush out unused constants.  I would be happy to accept a
> patch to do that.

Here is an implementation of this -- there are some things you might not 
like about it:

1) I had to make the private destroyConstantImpl method public to access 
it from the template class ValueMap since there is no good way to 
declare it as a friend.

2) I keep the types in a std::vector so I can easily drop all references 
and delete them without going through all the type maps - this adds a 
little bit of overhead, but there shouldn't be that many types (compared 
to constants), so to me it seems acceptable. This also means I can get 
by with a 'friend' declaration to get at the private data of the types 
when I want to forcefully drop references.

I dropped the memory pool thing because the use lists always 'new' one 
element, so I could not avoid calling the destructors of the constants 
even if they have no (real) uses...

m.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: memcleanup.txt
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20041115/1edddba3/attachment.txt>


More information about the llvm-dev mailing list