Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 321573 - memory leak when scaling an image
Summary: memory leak when scaling an image
Status: CLOSED WORKSFORME
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.0   Edit
Hardware: PC Linux
: P3 critical (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-03 06:36 EDT by Berthold Daum CLA
Modified: 2016-10-04 12:00 EDT (History)
4 users (show)

See Also:


Attachments
Test program to reproduce the error (1.17 KB, application/octet-stream)
2010-08-03 06:37 EDT, Berthold Daum CLA
no flags Details
Screenshot of system monitor after 1800 passes (63.05 KB, image/png)
2010-08-03 06:41 EDT, Berthold Daum CLA
no flags Details
System configuration (8.92 KB, text/plain)
2010-08-03 06:41 EDT, Berthold Daum CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Berthold Daum CLA 2010-08-03 06:36:27 EDT
Build Identifier: 20100617-1415

Memory in the X-Server is not released after an SWT image was drawn (GC.drawImage()) onto a smaller image (scaling down) and both images and the GC were disposed after the operation. Repeating these steps leads to a huge process memory footprint.
This was observed under Linux-GTK (Ubuntu 10.4). Not reproducible on Windows.

Reproducible: Always

Steps to Reproduce:
1. Run the attached program ImageScalingLeakTest.java
2. For each pass approx. 70k of memory is consumed
3. The attached screenshot was taken after 1800 passes
Comment 1 Berthold Daum CLA 2010-08-03 06:37:36 EDT
Created attachment 175761 [details]
Test program to reproduce the error
Comment 2 Berthold Daum CLA 2010-08-03 06:41:08 EDT
Created attachment 175762 [details]
Screenshot of system monitor after 1800 passes
Comment 3 Berthold Daum CLA 2010-08-03 06:41:37 EDT
Created attachment 175763 [details]
System configuration
Comment 4 Felipe Heidrich CLA 2010-08-04 14:34:17 EDT
Works for me. I ran your snippet on my Linux machine (Fedora Core 11) and the memory did not go up like you said.
Comment 5 Berthold Daum CLA 2010-08-06 09:09:11 EDT
Can we do something to sort this out?
Comment 6 Felipe Heidrich CLA 2010-08-06 10:40:13 EDT
can you tell me exactly which calls is causing the leak ?
If you remove this line:
gc.drawImage(image, 0, 0, bounds.width, bounds.height, 0, 0, width,height);
does the leak stop ?
Comment 7 Berthold Daum CLA 2010-08-09 04:40:55 EDT
Yes, it is gc.drawImage() that causes the leak.
Comment 8 Felipe Heidrich CLA 2010-08-10 11:50:48 EDT
Works for me, try this snippet:

public static void main(String[] args) {
	
		int count = 10000;
		Display display = new Display();
		System.out.println("Write down the memory used by this process and hit enter");
		try {
			System.in.read();
		} catch (IOException e) {
		}
		Image image = new Image(display, 3200, 2400);
		Image thumbnail = new Image(image.getDevice(), 320, 240);
		GC gc = new GC(thumbnail);
		long time = System.currentTimeMillis();
		for (int i = 0; i < count; i++) {
			gc.drawImage(image, 0, 0, 3200, 2400, 0, 0, 320, 240);
		}
		System.out.println(System.currentTimeMillis() - time);

		gc.dispose();
		image.dispose();
		thumbnail.dispose();
		System.gc();
		System.out.println("Compare the memory used by this process now to the initial mark, does it go up if count goes up ?");
		try {
			System.in.read();
		} catch (IOException e) {
		}
		display.dispose();
	}


For me it starts with 8.1mb and ends with 9mb, it doesn't matter the value for count (I tested with 1 and 10000). I also check all the code, no leaks anywhere.
Comment 9 Berthold Daum CLA 2010-08-10 17:05:47 EDT
Here is the reading from the system monitor, before and after:

Before:

Virtual 514.1 MB
Resident 25.4 MB
Writable 10.9 MB
Shared 14.6 MB
XServer 1.0 kB


After:

Virtual 1.0 GB
Resident 411.8 MB
Writable 399.7 MB
Shared 10.5 MB
XServer 30 MB
Comment 10 Felipe Heidrich CLA 2010-08-12 16:04:04 EDT
What is the version of X server are you running ?
My guess this is a bug in the X server.

Silenio, do you have ubuntu 10.4 ? can you try the snippet ?
Comment 11 Silenio Quarti CLA 2010-08-13 10:28:34 EDT
Tried the snippet on Ubuntu 10.04. Let it run around 3000 iterations. Memory usage is stable.
Comment 12 Berthold Daum CLA 2010-08-13 17:49:31 EDT
XServer version is 7.5+5ubuntu1

In the meantime I found the following: https://bugs.launchpad.net/ubuntu/+source/xorg-server/+bug/565981

Looks somehow similar.
Comment 13 Eric Williams CLA 2016-10-04 12:00:25 EDT
I can't reproduce this issue, and comment 12 points to an issue outside of SWT.