[Top][All Lists]
[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 18:13:23 +0100 |
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)
you can see which classes derive from ref_counted.
Those classes do support ref-counting.
When you construct a ref_counted class it's initial ref-count is 0.
The reccomandation would be to always store allocated ref_counted
objects to an intrusive_ptr:
boost::intrusive_ptr<as_array_object> array(new as_array_object());
This way you will be sure that the as_array_object will be deleted
when your function returns *unless* somebody else did increment
it's reference counter.
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();
}
--strk;
- [Gnash-dev] Memory allocation model?, Michael Meier, 2006/11/21
- Re: [Gnash-dev] Memory allocation model?, Michael Meier, 2006/11/21
- Re: [Gnash-dev] Memory allocation model?,
strk <=
- Re: [Gnash-dev] Memory allocation model?, Michael Meier, 2006/11/21
- Re: [Gnash-dev] Memory allocation model?, strk, 2006/11/21
- Re: [Gnash-dev] Memory allocation model?, Michael Meier, 2006/11/21
- Re: [Gnash-dev] Memory allocation model?, strk, 2006/11/21
- Re: [Gnash-dev] Memory allocation model?, Michael Meier, 2006/11/21
- Re: [Gnash-dev] Memory allocation model?, strk, 2006/11/21
- Message not available
- Re: [Gnash-dev] Memory allocation model?, strk, 2006/11/21
- Re: [Gnash-dev] Memory allocation model?, Michael Meier, 2006/11/21