gnash-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnash-dev] Memory allocation model?


From: strk
Subject: Re: [Gnash-dev] Memory allocation model?
Date: Tue, 21 Nov 2006 20:07:24 +0100

On Tue, Nov 21, 2006 at 07:13:37PM +0100, Michael Meier wrote:
> 
> > On Tue, Nov 21, 2006 at 05:25:35PM +0100, Michael Meier wrote:
> > > Hello
> > > 
> > > Is there any documentation about the memory management model in gnash?
> > 
> > Unfortunately not, but looking at the doxygen documentation
> > (cd doc/C; make apidoc)
> 
> Can't build it, it says 
> make: *** No rule to make target `apidoc'.  Stop.

My fault, it was in 'doc', not in 'doc/C'.
Also, you need to give ./configure --enable-docbook

> > Note that it is *dengerous* not to use the intrusive_ptr. Consider
> > the following:
> > 
> > 
> >     void
> >     do_something(as_object* obj)
> >     {
> >             // store in a smart pointer to keep it
> >             // alive for whole duration of this function
> >             {
> >                     boost::intrusive_ptr<as_objecte> holdit(obj);
> >                     // ref-count is incremented
> >             }
> > 
> >             // out of scope, ref-count is decremented,
> >             // if 0 obj is deleted !
> >     }
> > 
> >     void
> >     dangerous()
> >     {
> >             as_object* myobj = new as_object(); // ref-count == 0
> >             do_something(myobj); // WARNING: myobj is not deleted !!!
> >             as_object* proto = myobj->get_prototype();
> >     }
> 
> ? Isn't myobj deleted? The initial ref-count is 0. Then it is
> incremented in do_something in order to the creation of a intrusive_ptr
> instance. Then the gets out of scope, the ref-count is decremted, so
> it's 0 again. Because it reaches zero, obj will be deleted. So void

Exactly.

> dangerous is dangerous because it calls a method of myobj which got the
> deleted. (the instance, at least) I'm confused :)

Dangerous is dangerous because it doesn't wrap the pointer it creates
into a "smart" pointer for management.
If that function stored the return of 'new' into an intrusive_ptr
the object would not be deleted.


--strk;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]