Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 335891

Summary: Resizable Tracker leaks Cursor on Mac OSX
Product: [Eclipse Project] Platform Reporter: Scott Kovatch <skovatch>
Component: SWTAssignee: Scott Kovatch <skovatch>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: creichen, daniel_megert, eclipse.felipe, gheorghe, kleind, Mike_Wilson, skovatch, wtracey
Version: 3.6.1Flags: Mike_Wilson: pmc_approved+
eclipse.felipe: review+
gheorghe: review+
Target Milestone: 3.6.2   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Bug Depends on: 329499    
Bug Blocks:    
Attachments:
Description Flags
Patch for Carbon & Cocoa none

Description Scott Kovatch CLA 2011-01-31 14:03:20 EST
Cloning for 3.6.2 and Carbon/Cocoa. Fix is the same on both platforms.

+++ This bug was initially created as a clone of Bug #329499 +++

Build Identifier: org.eclipse.swt_3.6.1

When creating and resizing a Tracker on Mac OSX, a Cursor is leaked.


package st.snippets;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.DeviceData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tracker;


public class TrackerMouseDown2 {

	//Adapted from Snippet23.java
	//http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet23.java
	
	private static Point initialPoint = new Point(0, 0);
	private static boolean createResizableTracker = true;
	
	public static void main(String[] args) {
		DeviceData data = new DeviceData();
		data.tracking = true;
		Display display = new Display(data);
		Sleak sleak = new Sleak();
		sleak.open();
		
		final Shell shell = new Shell(display);
		shell.open();
		shell.addListener(SWT.MouseDown, new Listener() {
			
			public void handleEvent(Event e) {
				initialPoint = Display.getDefault().getCursorLocation();
				if (createResizableTracker) {
					createResizableTracker();
				}
				else {
					createStaticTracker(e);
				}
			}
		});
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}
	
	private static void createStaticTracker(Event e) {
		final Tracker tracker = new Tracker(Display.getDefault(), SWT.NONE);
		tracker.setRectangles(new Rectangle[] { new Rectangle(e.x, e.y, 100, 100), });
		System.out.println("Opening static tracker");
		tracker.open();
	}

	private static void createResizableTracker()
	{
		final Tracker tracker = new Tracker(Display.getDefault(), SWT.RESIZE);
//		tracker.setStippled(true);
		tracker.setRectangles(new Rectangle[] { new Rectangle(initialPoint.x, initialPoint.y, 1, 1) });

		System.out.println("Opening resizable tracker");
		tracker.open();
		try {
			System.out.println("Would open edit snapshot shell here");
		} catch (Throwable t) {
			t.printStackTrace();
		}
	}

Reproducible: Always

Steps to Reproduce:
See snippet above, which uses Sleak:
http://www.eclipse.org/articles/swt-design-2/sleak.htm

Start snippet to reveal canvas.
"Snap" Sleak
Click on canvas and drag the tracker.
Repeat
"Diff" Sleak
For each tracker created there is a leaked NSCursor.
Comment 1 Scott Kovatch CLA 2011-01-31 14:12:40 EST
Created attachment 187996 [details]
Patch for Carbon & Cocoa

Same fix on Carbon and Cocoa for 3.6.2
Comment 2 Dani Megert CLA 2011-02-01 02:44:24 EST
NOTE: You must get PMC approval to fix any bug after RC2.

Please fill out the following sections:
- GOALS/BENEFITS:
- RISKS:
- PERFORMANCE IMPACTS:
Comment 3 Scott Kovatch CLA 2011-02-01 11:36:59 EST
(In reply to comment #2)
> NOTE: You must get PMC approval to fix any bug after RC2.
> 
> Please fill out the following sections:
> - GOALS/BENEFITS:

This fix was already applied to 3.7 HEAD and is working well there. It was specifically requested by a customer to address a significant resource leak in their product that won't move to 3.7 for some time.

> - RISKS:

Low to none. This change is already in platforms other than carbon and cocoa, and is known to be correct.

> - PERFORMANCE IMPACTS:

Reduced memory footprint due to Cursor resources being freed when they should be.
Comment 4 Scott Kovatch CLA 2011-02-01 16:33:06 EST
Fixed in R3_6_maintenance branch > 20110201 in both carbon and cocoa.