Re: [api-dev] Question about weak reference list inside java bridge code.

2009-11-23 Thread Stephan Bergmann
See my answer to the same question at d...@udk.openoffice.org.  Lets keep 
discussion to that single mailing list.


-Stephan

-
To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org



[api-dev] Question about weak reference list inside java bridge code.

2009-11-22 Thread Huaidong Qiu
We got a problem like this, one of the L2 entry list keep growing consume
too much memory.

module jurt

package com.sun.star.lib.uno.environments.java;

the cleanUp member function of class Registry.

// must only be called while synchronized on map:
private void cleanUp() {
for (;;) {
Level2Entry l2 = (Level2Entry) queue.poll();
if (l2 == null) {
break;
}
// It is possible that a Level2Entry e1 for the OID/type
pair
// (o,t) becomes weakly reachable, then another Level2Entry
e2
// is registered for the same pair (o,t) (a new Level2Entry
is
// created since now e1.get() == null), and only then e1 is
// enqueued.  To not erroneously remove the new e2 in that
case,
// check whether the map still contains e1:
String oid = l2.getOid();
Level1Entry l1 = getLevel1Entry(oid);
if (l1 != null  l1.get(l2.getType()) == l2) {
removeLevel2Entry(oid, l1, l2);
}
}
}

All those weak reference Level2Entry entries are invalid, the condition
(l1.get(l2.getType()) == l2) keeps cleanUp function from removing them from
the list.

I think if this
// It is possible that a Level2Entry e1 for the OID/type
pair
// (o,t) becomes weakly reachable, then another Level2Entry
e2
// is registered for the same pair (o,t) (a new Level2Entry
is
// created since now e1.get() == null), and only then e1 is
// enqueued.
happened once then there is no way the condition (l1.get(l2.getType()) ==
l2) can be true again, because get(l2.getType()) always return the first
element in the list, but queue.poll() return the newly released weak
reference which can not be the first one in the list.

If weak reference list cleanup mechanism is correct, could please give some
possible reasons could cause the growing problem of L2 entry list.


Thanks.

Huai Dong