Hi,<br><br>I'm seeing rather high memory usage from LLVM and I'd like to track down what I'm doing to cause it. My application is a simple web application server that compiles web pages with embedded script to bitcode and compiles them with the JIT on demand. I've taken tools/lli.cpp as a starting point and extended it to load additional modules.<br>
<br>However, if I load successive pages and watch top, my RSS size increases by roughly 40 times the on disk size of the loaded bit code for each loaded module, which I take to mean I have a massive leak. I'm probably just not freeing stuff that I ought to but I don't know what - deleting the MemoryBuffer or ModuleProvider results in a SEGV. I've read the doxygen docs but I'm not clear what objects have allocated what memory for what purpose, what can be freed once all functions in a module have been compiled or how to do this.<br>
<br>I'd be grateful if anyone could tell me what I'm doing wrong or point me at docs or examples covering this topic? The gist of my code is:<br><br>Module *load_module(char *bitcode_name) {<br>  MemoryBuffer *buffer = MemoryBuffer::getFile(bitcode_name, 
&error_message);<br>
  ModuleProvider *mp = getBitcodeModuleProvider(buffer, 
getGlobalContext(), &error_message);<br>
<br>  if( first_time ) {<br>      InitializeNativeTarget();<br>      builder = new EngineBuilder(mp);<br>      builder->setEngineKind(EngineKind::JIT);<br>      CodeGenOpt::Level opt_level = CodeGenOpt::Default;<br>      builder->setOptLevel(opt_level);<br>
      execution_engine = builder->create();<br>      delete(builder);       // lli doesn't do this - is it safe? <br>  }<br><br>  Module *module = mp->materializeModule(&error_message);<br>  for (Module::iterator I = module->begin(), E = module->end(); I != E; ++I) {<br>
    Function *f = &*I;<br>    if(!f->isDeclaration()) {<br>      execution_engine->getPointerToFunction(f);<br>    }<br>  }<br>  // all functions are compiled so I'd like to dispose of the bitcode any memory used in the compilation - how can I do this?<br>
  execution_engine->runStaticConstructorsDestructors(false);<br><br>  return module;<br>}<br><br>-- James Williams<br><br>