[gecode-users] VarArray<Var>::resize(Space& home, int m)

Guido Tack tack at ps.uni-sb.de
Thu Oct 15 17:07:34 CEST 2009


Hi David,

David Rijsman wrote:
> I have a question on the method "void  VarArray<Var>::resize(Space&  
> home, int m)".
>
> I am on version 2.1.1 and noticed the method has changed somewhere  
> between version 2.1.1 and the 3.2.0. I can not find any reason in  
> the change list for the change.
>
> I noticed this because I am, what I think, experiencing a memory  
> leak. I am resizing my IntVarArray during execution which forces it  
> to be allocated on the heap. In the destructor of the array there is  
> a check to see if we need to free the heap, the check in (2.1.1)  
> looks like " if (used != n) ". I think this check is failing in my  
> case and therefor the heap does not get freed.
>
> The changes made to "VarArray<Var>::resize(Space& home, int m)" seem  
> to influence the values 'used' and 'n' (they have been named  
> differently now). Has the change been made to prevent a memory leak?

Yes, exactly.  The logic in 2.1.1 is completely flawed.

> Being on the topic, what is the reason for resizing it on the heap  
> instead of keeping it in the Space which is available?

That would possibly create a memory leak in the space, as the old  
array cannot easily be reused (it will be handed back to the space,  
but then it can only be used for freelist-allocated data).

Cheers,
	Guido





More information about the gecode-users mailing list