Miguel,

You're adding a new element to the 'ao' array in each
loop, and you're not removing these array elements later
(just assigning 0 to them). So you end up with an array
of 1500 zero values, each zero is one item, that's where
memory is 'lost'.

Brgds,
Viktor

On 2008.04.28., at 10:19, Miguel Angel Marchuet wrote:

#include "hbmemory.ch"
#include "hbclass.ch"

#ifndef __XHARBOUR__
#xtranslate Str( <x>, <y>, <z>, .F. ) => Str( <x>, <y>, <z> )
#xtranslate Str( <x>, <y>, <z>, .T. ) => LTrim( Str( <x>, <y>, <z> ) )
#xtranslate Str( <x>, <y>, <z>, <k> ) => If( <k>, LTrim( Str( <x>, <y>, <z> ) ), Str( <x>, <y>, <z> ) )
#include "xhb.ch"
#endif

#ifdef DEFAULT
#UNDEF DEFAULT
#endif
#xcommand DEFAULT <v1> := <x1> [, <vn> := <xn> ] => ;
         If( <v1> == nil, <v1> := <x1>, ) ;
         [; If( <vn> == nil, <vn> := <xn>, ) ]

#define MAXTEST 1500


PROCEDURE MAIN()
  LOCAL n, ao := {}, nMem

  REQUEST HB_GT_WIN

  FOR n := 1 TO MAXTEST

     // here loose Harbour
     aAdd( ao, PROBLEM() )
     // ------------------

     ao[-1] := 0
     hb_gcAll( .T. )

     // Here loose xHarbour
     DEFAULT nMem := Memory( HB_MEM_USED )
     //--------------------

     #ifdef __XHARBOUR__
? 'Mem used -> ' + AllTrim( Str( Memory( HB_MEM_USED ) ) ) + " on " + AllTrim( Transform( Memory( HB_MEM_BLOCKS ), '@E 999,999,999' ) ) + " bloqs"
     #else
        ? 'Mem used -> ' + AllTrim( Str( Memory( HB_MEM_USED ) ) )
     #endif

     IF n == MAXTEST
? "We lost " + AllTrim( Str( Memory( HB_MEM_USED ) - nMem ) ) + " Bytes"
     ENDIF

  NEXT

RETURN

FUNCTION PROBLEM()
  LOCAL cValue := {'   '}
  LOCAL oMem1 := Mem():New()
RETURN Ctl():New( oMem1, bSetGet( cValue, 1 ), 'XXXX' )

CLASS Mem
  DATA aValues INIT {}
  DATA oFriend
  METHOD New( oFriend ) CONSTRUCTOR
  METHOD AddItem( oItem ) INLINE AAdd( ::aValues, oItem )
ENDCLASS

METHOD New( oFriend ) CLASS Mem
  //::aValues := { 1, "TEST", Date(), {}, {=>} }

  IF ! Empty( oFriend )
     ::oFriend := oFriend
     oFriend:AddItem( Self )
  ENDIF

RETURN Self

CLASS Ctl
  DATA oFriend
  DATA oGet
  METHOD New( oFriend, bSetGet, cPict ) CONSTRUCTOR
ENDCLASS

METHOD New( oFriend, bSetGet, cPict ) CLASS Ctl
  oFriend:AddItem( Self )
  ::oFriend := oFriend
  ::oGet    := GetNew( 20, 20, bSetGet,, cPict )
RETURN Self

FUNCTION bSetGet( uVar, nVal )
RETURN {|u| If( PCount() > 1, uVar[nVal] := u, uVar[nVal] ) }
_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to