Bug 331232 - There are memory leaks with each GDB debug session
Summary: There are memory leaks with each GDB debug session
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-debug-dsf (show other bugs)
Version: 8.0   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-26 13:55 EST by Dobrin Alexiev CLA
Modified: 2020-09-04 15:20 EDT (History)
6 users (show)

See Also:


Attachments
We need to unistall the proxy... (1.90 KB, patch)
2010-11-26 14:02 EST, Dobrin Alexiev CLA
no flags Details | Diff
Missing things in GdbAdapterFactory (1.36 KB, patch)
2010-11-26 14:47 EST, Marc Khouzam CLA
marc.khouzam: iplog-
Details | Diff
Fix memory leaks (5.40 KB, patch)
2011-05-13 03:47 EDT, Anton Leherbauer CLA
aleherb+eclipse: iplog-
Details | Diff
Fix for ReverseToggleCommandHandler (1.55 KB, patch)
2011-05-16 08:11 EDT, Anton Leherbauer CLA
aleherb+eclipse: iplog-
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dobrin Alexiev CLA 2010-11-26 13:55:08 EST
Build Identifier: Build id: M20100909-0800

Start and termiante GDB debug session.
 
See that there are leaks of org.eclipse.cdt.dsf.gdb.internal.ui.viewmodel.launch.LaunchVMProvider that don't get garbadge collected.

Reproducible: Always

Steps to Reproduce:
Start and termiante GDB debug session.
 
See that there are leaks of org.eclipse.cdt.dsf.gdb.internal.ui.viewmodel.launch.LaunchVMProvider that don't get garbadge collected.
Comment 1 Dobrin Alexiev CLA 2010-11-26 14:02:36 EST
Created attachment 183947 [details]
We need to unistall the proxy...

This is not sufficient... I'll keep looking for other places...
Comment 2 Marc Khouzam CLA 2010-11-26 14:47:16 EST
Created attachment 183951 [details]
Missing things in GdbAdapterFactory

I also found stuff in GdbAdapterFactory.  But I still see leaks.
Comment 3 Dobrin Alexiev CLA 2010-11-26 15:54:00 EST
With the first patch (LaunchRootVMNode) I decreased the reference to DefaultVMModelProxyStrategy to two. 
The next two I think are coming from: AbstractCachingVMProvider (line 921) 
	The DefaultVMModelProxyStrategy is added to fActiveModelProxies but is never removed. 
	I expected at some point that instance to be removed from the list fActiveModelProxies by calling rootElementRemovedFromCache(Object rootElement). 

At this moment I am not too familiar with AbstractCachingVMProvider. 
I hope someone that has played more with this class give us a suggestion. 
I'll keep digging...
Comment 4 CDT Genie CLA 2010-11-30 10:23:07 EST
*** cdt cvs genie on behalf of mkhouzam ***
Bug 331232: Missing some unregistering

[*] GdbAdapterFactory.java 1.16 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/GdbAdapterFactory.java?root=Tools_Project&r1=1.15&r2=1.16
Comment 5 Marc Khouzam CLA 2010-11-30 10:59:13 EST
(In reply to comment #2)
> Created an attachment (id=183951) [details]
> Missing things in GdbAdapterFactory
> 
> I also found stuff in GdbAdapterFactory.  But I still see leaks.

I committed this patch to HEAD and 7_0
Comment 7 Pawel Piech CLA 2010-11-30 13:12:41 EST
(In reply to comment #6)
> *** cdt cvs genie on behalf of mkhouzam ***
> Bug 331232: Missing unregisters
> 
> [*] GdbAdapterFactory.java 1.15.2.1
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/GdbAdapterFactory.java?root=Tools_Project&r1=1.15&r2=1.15.2.1

Hi Mark,
Did you notice whether this would re-introduce bug 293109?
Comment 8 Marc Khouzam CLA 2010-11-30 15:32:49 EST
(In reply to comment #7)
> (In reply to comment #6)
> > *** cdt cvs genie on behalf of mkhouzam ***
> > Bug 331232: Missing unregisters
> > 
> > [*] GdbAdapterFactory.java 1.15.2.1
> > http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/GdbAdapterFactory.java?root=Tools_Project&r1=1.15&r2=1.15.2.1
> 
> Hi Mark,
> Did you notice whether this would re-introduce bug 293109?

I tried it and the first time it failed!  The DV was missing an update.
But every other time after that, it worked properly (about 20 times).

Why would this change affect the Terminate and Relaunch?
Comment 9 Pawel Piech CLA 2010-11-30 15:42:22 EST
Calling session.unregisterModelAdapter(ILaunch.class); means that clients can't retrieve the launch object from an IDMContext.  I thought Terminate and Relaunch may be affected by this, but it appears that it's not.  Thanks for checking.
Comment 10 Anton Leherbauer CLA 2011-05-13 03:47:04 EDT
Created attachment 195562 [details]
Fix memory leaks

I did a little investigation triggered by bug 345164 and found a few leaks which prevent the cleanup of DsfSession and Spawner objects after a DSF-GDB launch is terminated and removed from the Debug view.

- Remove reference to executor instance from DefaultDsfExecutor.fThreadToExecutorMap when the executor terminates
- Avoid reference to DsfSession in AbstractDMContext, use session id instead
- Make GDBContainerDMC a static class in GDBProcesses_7_0
- Remove TracingConsole as service event listener on dispose

The only remaining leak (AFAICT) is the DefaultVMModelProxyStrategy which is covered by bug 345476.
With this patch applied and when I close the Debug view after the session is terminated (which disposes the model proxy), I can find no longer an instance of DsfSession or Spawner in the heap dump.
Comment 11 Vladimir Prus CLA 2011-05-13 03:51:38 EDT
Reference to DsfSession in AbstractDMContext was specifically used to keep the DsfSession alive, until there's AbstractDMContext that can access it. Unless there's some other clever solution to that, I believe this patch will reintroduce https://bugs.eclipse.org/bugs/show_bug.cgi?id=293109
Comment 12 Anton Leherbauer CLA 2011-05-13 04:07:47 EDT
(In reply to comment #11)
> Reference to DsfSession in AbstractDMContext was specifically used to keep the
> DsfSession alive, until there's AbstractDMContext that can access it. Unless
> there's some other clever solution to that, I believe this patch will
> reintroduce https://bugs.eclipse.org/bugs/show_bug.cgi?id=293109

Thanks, that's an interesting aspect. The main issue I saw with DMCs is that the editor annotation model holds references to the last annotation change.  I.e. if the last change was removing the IP annotation, this annotation is held back and with it a IFrameDMContext and DsfSession.
Removing the DsfSession reference seemed easier than fixing the annotation model.
Comment 13 Marc Khouzam CLA 2011-05-13 05:40:08 EDT
Thanks Toni, that is really awesome!

Just a note that if you enable the Reverse debugging buttons, there is one more leak in ReverseToggleCommandHandler, which I gather I haven't done such a good job with.  I'll try to get to it later today, unless you want to take care of it earlier.

org.eclipse.cdt.debug.internal.ui.commands.ReverseToggleCommandHandler@0x746f5518 (37 bytes) (field fActiveContext:)
--> org.eclipse.cdt.dsf.ui.viewmodel.datamodel.AbstractDMVMNode$DMVMContext@0x75b1a8e0 (20 bytes) (field fNode:)
--> org.eclipse.cdt.dsf.debug.ui.viewmodel.launch.StackFramesVMNode@0x750c8448 (33 bytes) (field fSession:)
--> org.eclipse.cdt.dsf.service.DsfSession@0x750ae010 (32 bytes)
Comment 14 Marc Khouzam CLA 2011-05-13 06:04:07 EDT
What do you say to committing the changes except the ones for AbstractDMContext.java?

I guess we can deal with AbstractDMContext.java in the next release, or do you have an idea?
Comment 15 Anton Leherbauer CLA 2011-05-13 06:42:32 EDT
(In reply to comment #14)
> What do you say to committing the changes except the ones for
> AbstractDMContext.java?

Done. The remaining changes should be safe.

> I guess we can deal with AbstractDMContext.java in the next release, or do you
> have an idea?

I think I'll file a bug with Platform/Text for the annotation model issue.  As for AbstractDMContext, I think it would make sense to separate model adapters from the DsfSession object, but that would need some API changes (similar to bug 252859).
Comment 17 Marc Khouzam CLA 2011-05-13 09:47:52 EDT
(In reply to comment #15)
> (In reply to comment #14)
> > What do you say to committing the changes except the ones for
> > AbstractDMContext.java?
> 
> Done. The remaining changes should be safe.

Thanks!
Comment 18 Anton Leherbauer CLA 2011-05-16 08:11:51 EDT
Created attachment 195723 [details]
Fix for ReverseToggleCommandHandler

I have committed this fix for the leak in ReverseToggleCommandHandler.
Comment 19 CDT Genie CLA 2011-05-16 08:23:05 EDT
*** cdt cvs genie on behalf of aleherbau ***
Bug 331232 - There are memory leaks with each GDB debug session (partial fix)

[*] ReverseToggleCommandHandler.java 1.5 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/all/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/commands/ReverseToggleCommandHandler.java?root=Tools_Project&r1=1.4&r2=1.5
Comment 20 Marc Khouzam CLA 2011-05-16 09:04:41 EDT
(In reply to comment #18)
> Created attachment 195723 [details]
> Fix for ReverseToggleCommandHandler
> 
> I have committed this fix for the leak in ReverseToggleCommandHandler.

Thanks Toni, I had to give my attention to some Restart issues for the RC1 build.