Closed Bug 36191 Opened 26 years ago Closed 24 years ago

Too many array classes, and a couple of them leak

Categories

(Core :: XPCOM, defect, P3)

defect

Tracking

()

RESOLVED FIXED

People

(Reporter: briansmith, Assigned: scc)

References

()

Details

(Keywords: memory-leak)

Attachments

(1 file)

There are two memory leaks in ns[C]StringArray: http://lxr.mozilla.org/seamonkey/source/xpcom/ds/nsVoidArray.cpp#307 http://lxr.mozilla.org/seamonkey/source/xpcom/ds/nsVoidArray.cpp#496 These delete the array of pointers without deleting the objects the pointers point to. The quick fix is to change |delete mArray;| to |Clear()|. I will submit a patch for this later in the day (when I get off work). My suggestion for a better fix for this bug is: 1. Move nsObjectArray and nsObject to XPCOM from i18n to XPCOM (http://lxr.mozilla.org/seamonkey/ident?i=nsObjectArray) (http://lxr.mozilla.org/seamonkey/ident?i=nsObject). This will provide a general solution for this type of problem, and I'm sure that many places besides XPCOM. 2. Have nsString and nsCString inherit from nsObject so that they that nsStringArray and nsCStringArray can be implemented using nsObjectArray 3. Reimplement nsCStringArray and nsStringArray using nsObjectArray. This will cut down on some code duplication in these classes. 4. Reimplement nsObjectArray on top of nsVoidArray, further reducing code duplication. There a bug on nsVoidArray (#29873) that I could fix in the process. Also, there is an item in the XPCOM TODO about removing the single dependency on nsVector (http://lxr.mozilla.org/seamonkey/ident?i=nsVector) so that nsVector and PLVector can be removed. I could take submit patches for this. The second bug on nsVoidArray (#26030) may require an interface change to that class and I'd like feedback before I try to tackle that one. Please let me know if you want me to go ahead with the changes I listed above. Perhaps the best part is that they have nothing to do with UTF-8! - Brian
Sorry, I cut the end of #1 off: "I'm sure that many places besides XPCOM and i18n would benefit from nsObjectArray".
This is so for scc.
Assignee: dp → scc
I submitted a context-diff patch implementing the "quick fix" mentioned above. The patch compiled and Mozilla runs with no noticable difference on my machine. I tried to do before-and-after leak reports but Mozilla would always hang when loading xpinstal.dll with logging enabled. The array classes can be made much simpler and smaller than they are now-- nsStringArray and nsCStringArray can be turned into wrapper classes and be inlined away to nothing. I will work on points (1)-(4) and bug #29873 above if scc approves.
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Target Milestone: --- → M18
mass re-assigning to my new bugzilla account
Assignee: scc → scc
Status: ASSIGNED → NEW
Status: NEW → ASSIGNED
QA Contact: leger → kandrot
OS: other → All
Hardware: PC → All
Target Milestone: M18 → ---
Blocks: 92580
No longer blocks: 92580
I verified that both the mentioned leaks do not exist in the current code. Array of pointers is being deleted only after deleting the objects the pointers point to. I'm not sure about the other suggestions as in that case inheritance will surely cause some overhead.
the leaks are fixed according to the last comment, and as to major re-design of collection classes... well.. someday but leaving _this_ bug open won't make it happen any sooner.
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: