|
|
Darren New <dne### [at] sanrrcom> wrote:
> As pointed out, this is part of what "weak references" were created for.
> If a GC runs and the only pointers to an object are "weak", then all the
> "weak" pointers get set to null, and your Engine can notice that and not
> try to use that pointer any more.
If the GC runs in parallel in its own thread, wouldn't there be a mutual
exclusion problem (even in 1-core processors)?
Let's assume the Engine object does this:
if(listeners[i] != null)
listeners[i].doSomething();
If the GC happens to make a sweep after the conditional but before
the call, and it sets the weak reference at listeners[i] to null, we'll
get a null pointer exception (which may seem crazy because we just
checked that it's not null).
Or are GC engines run only at places where there can't be mutual
exclusion problems? (How does the VM/compiler/interpreter know that?)
--
- Warp
Post a reply to this message
|
|