[Gambas-devel] How to know if an object is allocated or freed ?

Benoit Minisini gambas at ...1...
Wed Dec 15 17:07:04 CET 2004


On Tuesday 14 December 2004 22:16, Laurent Carlier wrote:
> How can i know if an object was freed ?
>
> GB.CheckObject test only if it's null.

GB.CheckObject tests if an object is null AND if it is valid, i.e. if the 
valid hook of the object class returns FALSE.

> It's should be good for me to avoid segfault.
>
> code :
> PUBLIC SUB Main()
>
>   DIM toto AS Buffer
>
>   Screen(800,600,32)
>   toto = NEW Buffer(800,600,32)
>
>   Draw.Buffer(toto)
>   toto = Screen.Grab()
>   Draw.Line(0,0,100,100)
>   WAIT 3
>
> END
>
> it segfault as toto has been freed but isn't a null object !
> How can i know if it was freed ?
> Perhaps an int GB.IsAllocated(void** object) function should be usefull.
>
> Regards,

You can know that an object is freed only in its '_free' method. You don't 
have to know that an object WAS freed, it is a nonsense. Because if an object 
was freed, it does not exist anymore, so you can't have any information about 
it.

Send your source code!

-- 
Benoit Minisini
mailto:gambas at ...1...




More information about the Devel mailing list