views:

60

answers:

3

I am looking for a way to cure at least the symptoms of a leaky DLL i have to use. While the library (OpenCascade) claims to provides a memory manager, i have as of yet being unable to make it release any memory it allocated.

I would at least wish to put the calls to this module in a 'sandbox', in order to keep my application from not losing memory while the OCC-Module isn't even running any more.

My question is: While I realise that it would be an UGLY HACK (TM) to do so, is it possible to preallocate a stretch of memory to be used specifically by the libraries, or to build some kind of sandbox around it so i can track what areas of memory they used in order to release them myself when i am finished?

Or would that be to ugly an hack and I should try to resolve the issues otherwise?

+6  A: 

The only reliable way is to separate use of the library into a dedicated process. You will start that process, pass data and parameters to it, run the library code, retrieve results. Once you decide the memory consumption is no longer tolerable you restart the process.

sharptooth
Yes, and if it crashes you're protected as well.
Matthieu M.
+3  A: 

Using a library that isn't broken would probably be much easier, but if a replacement ins't available you could try intercepting the allocation calls. If the library isn't too badly 'optimized' (specifically function inlining) you could disassemble it and locate the malloc and free functions; on loading, you could replace every 4 (or 8 on p64 system) byte sequence that encodes that address with one that points to your own memory allocator. This is almost guaranteed to be a buggy, unreadable timesink, though, so don't do this if you can find a working replacement.

Edit:

Saw @sharptooth's answer, which has a much better chance of working. I'd still advise trying to find a replacement though.

David X
+1 for A good answer, virtual +1 for 'buggy, unreadable timesink'. That one (timesink) should be on the list of 'programming terms you coined'(http://stackoverflow.com/questions/2349378/new-programming-jargon-you-coined) which, alas, has been locked
sum1stolemyname
@sum1stolemyname, actually "timesink" is from electrical engineering (or something) 's "current sink" (or just "sink"): "somthing that can, in theory, sink (absorb) an unlimited amount of [time]". Not my coinage by a long shot.
David X
@David Ture about the .*sink, but the construction timesink _is_ a term i never heard before. My fault. http://en.wikipedia.org/wiki/Timesink
sum1stolemyname
A: 

You should ask Roman Lygin's opinion - he used to work at occ. He has at least one post that mentions memory management http://opencascade.blogspot.com/2009/06/developing-parallel-applications-with_23.html.

If you ask nicely, he might even write a post that explains mmgt's internals.

Mark