Jump to page: 1 2
Thread overview
Re: Number of references to a Class Object
Feb 12, 2011
Andrew Wiley
Feb 12, 2011
d coder
Feb 12, 2011
bearophile
Feb 12, 2011
Simon Buerger
Feb 12, 2011
d coder
Feb 12, 2011
bearophile
Feb 12, 2011
Jonathan M Davis
Feb 12, 2011
d coder
Feb 14, 2011
Stanislav Blinov
Feb 14, 2011
spir
Feb 12, 2011
spir
Feb 12, 2011
Jonathan M Davis
Feb 13, 2011
d coder
February 12, 2011
On Sat, Feb 12, 2011 at 1:20 AM, d coder <dlang.coder@gmail.com> wrote:
> Greetings
>
> I am in a situation where I need to know the number of references to a class' object. To explain, I have an array of class objects and I occasionally process this array. But if a particular object in this array is not being garbage collected just because it is part of this array, I would like to loose that object by making it null.

I believe what you're referring to is generally called a Weak
Reference, which is a reference that the GC doesn't consider when
deciding to keep an object alive, but that the GC will update if an
object dies.
There's a feature request at http://d.puremagic.com/issues/show_bug.cgi?id=4151
February 12, 2011
> I believe what you're referring to is generally called a Weak
> Reference, which is a reference that the GC doesn't consider when
> deciding to keep an object alive, but that the GC will update if an
> object dies.
> There's a feature request at http://d.puremagic.com/issues/show_bug.cgi?id=4151
>

Thanks Andrew

Is there a way fro the users like myself to vote up an issue on DMD Bugzilla.

Regards
- Cherry
February 12, 2011
d coder:

> Is there a way fro the users like myself to vote up an issue on DMD Bugzilla.

In this case I think voting is not so useful. I think that actually implementing weak references is better (and later they may be added to Phobos). It requires some work and knowledge of D and its GC. rebindable() may be used as a starting point to copy from...

Bye,
bearophile
February 12, 2011
On 02/12/2011 08:33 AM, d coder wrote:
>> I believe what you're referring to is generally called a Weak
>> Reference, which is a reference that the GC doesn't consider when
>> deciding to keep an object alive, but that the GC will update if an
>> object dies.
>> There's a feature request at http://d.puremagic.com/issues/show_bug.cgi?id=4151
>>
>
> Thanks Andrew
>
> Is there a way fro the users like myself to vote up an issue on DMD Bugzilla.

Yes, just register at the issue tracker (http://d.puremagic.com/issues/), then you can vote.
About the feature of weak refs, Lua and... miniD have it. A quick search should tell you more if you like.

Deins
-- 
_________________
vita es estrany
spir.wikidot.com

February 12, 2011
On 12.02.2011 11:47, bearophile wrote:
> d coder:
>
>> Is there a way fro the users like myself to vote up an issue on DMD Bugzilla.
>
> In this case I think voting is not so useful. I think that actually implementing weak references is better (and later they may be added to Phobos). It requires some work and knowledge of D and its GC. rebindable() may be used as a starting point to copy from...
>
> Bye,
> bearophile

Also tango (for D 1.0) implements it.
Link: http://www.dsource.org/projects/tango/docs/current/tango.core.WeakRef.html

Might be worth a look if you are going to implement it for D 2.0.

- Krox
February 12, 2011
> Also tango (for D 1.0) implements it.
> Link:
> http://www.dsource.org/projects/tango/docs/current/tango.core.WeakRef.html
>
> Might be worth a look if you are going to implement it for D 2.0.
>

I looked at the D1 implementation. It depends on GC methods weakPointerCreate and weakPointerDestroy. These functions are implemented in D1 GC as extern C functions.

It seems most of this code should be directly portable to D2, it would certainly require changes in the DMD2 source code. I have never worked at that level and have used D2 only for past couple of months. While I can give that a blind try,  it would be useful only if it gets excepted in DMD2.

What do you guys suggest?

Regards
- Cherry
February 12, 2011
On Saturday 12 February 2011 07:44:05 d coder wrote:
> > Also tango (for D 1.0) implements it.
> > Link:
> > http://www.dsource.org/projects/tango/docs/current/tango.core.WeakRef.htm
> > l
> > 
> > Might be worth a look if you are going to implement it for D 2.0.
> 
> I looked at the D1 implementation. It depends on GC methods weakPointerCreate and weakPointerDestroy. These functions are implemented in D1 GC as extern C functions.
> 
> It seems most of this code should be directly portable to D2, it would certainly require changes in the DMD2 source code. I have never worked at that level and have used D2 only for past couple of months. While I can give that a blind try,  it would be useful only if it gets excepted in DMD2.
> 
> What do you guys suggest?

If it's Tango code, don't port it. That would cause licensing issues.

If you know roughly what to do and want to take a stab at producing a viable patch to fix the problem, then feel free. If it's solid, it may get in. I don't know. It doesn't hurt to try though (as long as you're prepared for the fact that it may not be accepted).

- Jonathan M Davis
February 12, 2011
d coder:

> What do you guys suggest?

I suggest you to be very careful before "adapting" code from Tango, because of troublesome license issues :-(

Bye,
bearophile
February 12, 2011
> If you know roughly what to do and want to take a stab at producing a viable patch to fix the problem, then feel free. If it's solid, it may get in. I don't know. It doesn't hurt to try though (as long as you're prepared for the fact that it may not be accepted).

Thanks for letting me know of the licensing issues. I do not think I have the expertize required to fix this myself. So I hang my shoes here and wait for somebody else to get stuck in a similar situation.

Regards
- Cherry
February 12, 2011
On Saturday 12 February 2011 08:45:03 d coder wrote:
> > If you know roughly what to do and want to take a stab at producing a viable patch to fix the problem, then feel free. If it's solid, it may get in. I don't know. It doesn't hurt to try though (as long as you're prepared for the fact that it may not be accepted).
> 
> Thanks for letting me know of the licensing issues. I do not think I have the expertize required to fix this myself. So I hang my shoes here and wait for somebody else to get stuck in a similar situation.

It is a known issue, and it should probably be fixed at some point, but I don't think that it's a high priority. So, there's a decent chance that it will be dealt with, but I have no idea when.

However, it's not generally an issue, because you shouldn't normally be keeping references around for stuff that isn't used anymore. The garbage collector is smart enough to deal with circular references and the like, so the biggest cases where you'd normally need weak references aren't actually a problem. You're trying to do something fairly abnormal here.

- Jonathan M Davis
« First   ‹ Prev
1 2