Closed Bug 274793 Opened 20 years ago Closed 16 years ago

leaking JS atoms and GC roots

Categories

(Calendar :: Internal Components, defect)

x86
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: mvl, Assigned: dbo)

References

Details

Attachments

(3 files)

I get these errors when trying to parse a ics file into events, and put those
events in a memory calendar:

JS engine warning: 2 atoms remain after destroying the JSRuntime.
                   These atoms may point to freed memory. Things reachable
                   through them have not been finalized.
JS engine warning: leaking GC root 'XPCVariant::mJSVal' at 0x8147e4c
JS engine warning: 1 GC root remains after destroying the JSRuntime.
                   This root may point to freed memory. Objects reachable
                   through it have not been finalized.

i see the first error all the time, but the seconds seems to be more interesting
Attached file testcase —
Attached file another testcase —
Using this testcase, i get warnings about leaks. But when i remove the rrule,
the warnings are gone.
If I remove the ref from calItemBase to the parent, the leaks are gone. There is
a circular reference: the calendar has a ref to the events, and the events back
to the calendar.
I propose making the link back to the parent be a weak ref (internally to
calEvent; we would QIReferent and pass back a strong ref to callers, or else
null, as we currently do).
Assignee: shaver → vladimir
The changes in comment 3 won't fix testcase 2 (rrule based leaks), but i guess
that has the same kind of problem (circular ref between calRecurrenceInfo and
calItemBase)
Attached patch getting rid of wrappers — — Splinter Review
I suspect that native wrappers (+circular references) are the problem, too, thus spidermonkey doesn't gc those objects. This patch evaluates to get rid of them by storing the "wrappedJSObject"s being passed items/calendars only. This fixes the unit test warnings, but doesn't make bug 367456 any better. mvl, do you see any missing code pieces?
Flags: wanted-calendar0.8?
Daniel, is there a reason why you did not request review? from mvl?
Flags: wanted-calendar0.8? → wanted-calendar0.8+
Comment on attachment 284953 [details] [diff] [review]
getting rid of wrappers

>                 var event = Components.classes["@mozilla.org/calendar/event;1"]
>                                       .createInstance(Components.interfaces.calIEvent);
>-                item = event;
>+                item = event.wrappedJSObject;

I was sure I already posted my comments, but it seems I remembered wrong. So here it my comment: I don't like this code pattern. It totally breaks xpcom. What if calIEvent is implemented in C++? It would not work at all.
I don't have huge problems with forcing the calIEvent implementation to be written in javascript, but then we should not use the xpcom way to create an instance. But I would prefer to not force things like that, and stay more general.

And, if we get rid of the wrappers, I don't think that this would be fixed. The error might go away, but I think there are still the same circular references, and thus leaks. They are just not detected by xpconnect, because that's no longer in the loop.
(In reply to comment #8)
> I was sure I already posted my comments, but it seems I remembered wrong. So
...

Yes, we've already chatted about this some months ago. The mentioned patch was just a proof of concept that those js wrappers actually cause some leaks. After unwrapping those references, the leak warnings went away. A real fix of the problem will probably make use of weak references.


> And, if we get rid of the wrappers, I don't think that this would be fixed. The
> error might go away, but I think there are still the same circular references,
> and thus leaks. They are just not detected by xpconnect, because that's no
> longer in the loop.

Circular references per se are not provoking leaks if gc could properly track all objects that take part. Since js/native wrappers hinder the engine from doing so, we could use weak references here.
There might be more leaks, but we this shouldn't hinder us from fixing the known ones.
What's the bug number for the underlying leak problem?  It doesn't sound like this pattern should cause leaks, so if it is please file an XPConnect bug with test case.
I suspect that the cause of the leaks here is that there are also C++ components. calRecurrenceInfo has a list of calRecurrenceRule and calReucrrenceDate, which are  c++. There might be some cycle there, with closures, refcounting and all that.
Flags: wanted-calendar0.8+ → wanted-calendar0.9+
The test case has been fixed with checkins for bug 423172: The leaking gc roots have vanished (though 5 atoms remain).
Status: NEW → RESOLVED
Closed: 16 years ago
Depends on: 423172
Resolution: --- → FIXED
Target Milestone: --- → 0.9
Assignee: nobody → daniel.boelzle
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: