[Gecode] Memory leak fixed: Important, read carefully

Christian Schulte schulte at imit.kth.se
Fri May 21 16:20:52 CEST 2004


Dear all,

after considerable effort I have been able to fix the memory leak in Gecode.
Instrumental in finding the leak has been valgrind, which is highly
recommended (thanks to Guido for bringing valgrind to my attention).
Valgrind actually also revelaed that Gecode wrongly assumes that malloc's
are 8-aligned, Sigh...

The leak was in static-pqueue and has been introduced by somebody who did -
in my opinion - something that I really don't appreciate much. Let me
clarify why. (I didn't look who was it, I hope it was not me... :-) )

Point one: There's no problem whatsoever if you don't know some things.
That's normal.

Point two: There's a big problem, if you don't know what you are doing but
do it anyway. This is TERRIBLE. Why? 

Ask, that's why we do development jointly.

Discuss, more than one person are MUCH MUCH smarter than a single person!

Then, some technical food for thought (the problem was with reference
counting):

 - Whenever you have a copying constructor, also have an assignment operator
and vice versa.
 - UNDERSTAND how they work!
 - In reference counting, you associate the counter with the resource (that
is the block of memory). 
 - All clients of that resource manipulate the shared counter.
 - There is really no point in having a counter per client as you want to
count resource usage.
 - You might want to read about auto_ptr or reference counting in some
material on GC.

Let me clarify: I am not angry because there was a bug. That's normal. I am
angry as the code showed so clearly that the person had not clue whatsoever
about the issue at hand. That's terrible. Ask instead!

Cheers
Christian

--
Christian Schulte, http://www.imit.kth.se/~schulte/ 





More information about the gecode-users mailing list