From: Donal K. Fellows on 25 Jan 2010 07:59 On 25 Jan, 12:10, pmarin <pacog...(a)gmail.com> wrote: > 1- have I got to unset explicitly all the variables that a I have set > in the constructor? No. They'll go very shortly afterwards when the namespace is torn down (immediately after the destructor call is done). > 2- Is there any case when the destructor is called automatically? Anything that causes the command to be deleted (and which leaves the interpreter itself working) will start the call of the destructor; overwriting the object with a [proc] would do it. This is because the call of the destructor is hung off a command delete trace; the destroy method could be trivially scripted as just calling 'rename [self] {}'. Donal.
From: pmarin on 25 Jan 2010 09:49 On Jan 25, 1:59 pm, "Donal K. Fellows" <donal.k.fell...(a)manchester.ac.uk> wrote: > On 25 Jan, 12:10, pmarin <pacog...(a)gmail.com> wrote: > > > 1- have I got to unset explicitly all the variables that a I have set > > in the constructor? > > No. They'll go very shortly afterwards when the namespace is torn down > (immediately after the destructor call is done). > > > 2- Is there any case when the destructor is called automatically? > > Anything that causes the command to be deleted (and which leaves the > interpreter itself working) will start the call of the destructor; > overwriting the object with a [proc] would do it. This is because the > call of the destructor is hung off a command delete trace; the destroy > method could be trivially scripted as just calling 'rename [self] {}'. > > Donal. I destroy the objects but Tcl is not releasing the memory, The class ony holds strings: What am I doing wrong? oo::class create Object { constructor {_type _val} { my variable type my variable val my variable marked set type $_type set val $_val set marked 0 } method val {} { my variable val return $val } method set_val {_val} { my variable val set val $_val } method marked {} { my variable marked return $marked } method set_marked {_val} { my variable marked set marked $_val } method type {} { my variable type return $type } destructor { rename [self] {} } }
From: Alexandre Ferrieux on 25 Jan 2010 10:18 On Jan 25, 3:49 pm, pmarin <pacog...(a)gmail.com> wrote: > > I destroy the objects but Tcl is not releasing the memory, The class > ony holds strings: > > What am I doing wrong? > > destructor { > rename [self] {} > } The destructor itself will be called as a side-effect of the rename. So you probably want: oo::class ... { destructor {puts DESTROY!!!} } proc destroyany ob {rename $ob {}} ::Object create o foo bar destroyany ::o => DESTROY!!! -Alex
From: pmarin on 25 Jan 2010 10:26 On Jan 25, 4:18 pm, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com> wrote: > On Jan 25, 3:49 pm, pmarin <pacog...(a)gmail.com> wrote: > > > > > I destroy the objects but Tcl is not releasing the memory, The class > > ony holds strings: > > > What am I doing wrong? > > > destructor { > > rename [self] {} > > } > > The destructor itself will be called as a side-effect of the rename. > So you probably want: > > oo::class ... { > destructor {puts DESTROY!!!} > } > > proc destroyany ob {rename $ob {}} > > ::Object create o foo bar > > destroyany ::o > > => DESTROY!!! > > -Alex Ok, but I still not releasing the memory. I am counting the objects with llength [info class instances Object] So I am sure that the objects are destroyed but Tcl does not free the memory.
From: Alexandre Ferrieux on 25 Jan 2010 10:41 On Jan 25, 4:26 pm, pmarin <pacog...(a)gmail.com> wrote: > > > proc destroyany ob {rename $ob {}} > > Ok, but I still not releasing the memory. I am counting > the objects with > llength [info class instances Object] > So I am sure that the objects are destroyed but Tcl does not free the > memory. Tested here, [info class instances Object] is empty after the [destroyany]. I suspect you have another object, leftover from an earlier test. Hint: instead of just reading [llength], print the actual list ! -Alex
|
Next
|
Last
Pages: 1 2 Prev: TclOO. Some destructor questions Next: CompIMAGE 2010: Call for Short Communications |