Re: set_weak_flag() for objects?
Henrik Grubbström <[email protected]>
| Newsgroups | gmane.comp.lang.pike.user |
|---|---|
| Organization | Roxen Internet Software AB |
| Message-ID | <[email protected]> |
On Wed, 21 Sep 2016, Arne Goedeke wrote:
> Weak references are resolved (i.e. objects which only have weak
> references are destructed) only if 1) the gc runs or 2) when a mapping
> is rehashed. This means that in your example the object is only
> destructed when the gc runs. In your situation I would recommend doing
> something like this:
>
> class FOO {
> private mixed _id;
>
> mixed `id() {
> return _id || this;
> }
> }
NB: There's a special case in the reference counting for variables
in objects of classes written in pure Pike, where direct circular
references aren't counted (cf PIKE_T_NO_REF_*), so the above
construction isn't strictly needed (but still recommended).
/grubba
--
Henrik Grubbström [email protected]
Roxen Internet Software AB