On Wed, 13 Jul 2022 08:58:38 GMT, Sergey Bylokhov <[email protected]> wrote:

> Don't we have a similar issue in the usage of records and queue? Is it 
> possible that the target object in the add method will be deallocated before 
> ref will be added to the records? 

Yes, I believe it can be deallocated before the reference to it is added to 
`records`.

> In that case, the next code in run method will fail:

    Reference<?> obj = queue.remove();
    obj.clear();
    DisposerRecord rec = records.remove(obj);
    rec.dispose();


Of this I am not so sure. When `target` object is deallocated in the middle of 
`add()`, then `ref.get()` (`Reference.get()`) returns `null`, but the above 
code doesn't do that. Neither does the `add()` method; `records` are indexed by 
the `Reference` object, not - by now deallocated - referent of that reference:

java.lang.ref.Reference<Object> ref;
...
records.put(ref, rec);

-------------

PR: https://git.openjdk.org/jdk/pull/9362

Reply via email to