Thread overview | ||||||
---|---|---|---|---|---|---|
|
June 25, 2010 Object removing own last reference. | ||||
---|---|---|---|---|
| ||||
void externalFunc(){} class C { .. int index_; int yay; void removeMe() { //remove last reference to this object objects[_index] = null; //other critical code memberFunc(); externalFunc(); } void memberFunc(){yay++} } Is there anything unsafe about his code? Like the GC removing the Object before calling memberFunc.. |
June 25, 2010 Re: Object removing own last reference. | ||||
---|---|---|---|---|
| ||||
Posted in reply to strtr | Hi, Shouldn't be as 'this' will keep the object alive as long as necessary. Mark |
June 25, 2010 Re: Object removing own last reference. | ||||
---|---|---|---|---|
| ||||
Posted in reply to strtr | strtr <strtr@sp.am> wrote: > > void externalFunc(){} > > class C > { > .. > int index_; > int yay; > void removeMe() > { > //remove last reference to this object > objects[_index] = null; > > //other critical code > memberFunc(); > externalFunc(); > } > void memberFunc(){yay++} > } > > Is there anything unsafe about his code? Like the GC removing the Object > before calling memberFunc.. A reference to it will still be on the stack, so it should be no problem. -- Simen |
June 25, 2010 Re: Object removing own last reference. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen kjaeraas | == Quote from Simen kjaeraas (simen.kjaras@gmail.com)'s article
> strtr <strtr@sp.am> wrote:
> >
> > void externalFunc(){}
> >
> > class C
> > {
> > ..
> > int index_;
> > int yay;
> > void removeMe()
> > {
> > //remove last reference to this object
> > objects[_index] = null;
> >
> > //other critical code
> > memberFunc();
> > externalFunc();
> > }
> > void memberFunc(){yay++}
> > }
> >
> > Is there anything unsafe about his code? Like the GC removing the Object before calling memberFunc..
> A reference to it will still be on the stack, so it should be no problem.
The "this" marksibly mentioned. Thanks peoples ;)
|
Copyright © 1999-2021 by the D Language Foundation