JDK-4790833 : Memory usage shoots way up using Clipboard.getContents()
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.1
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2002-12-09
  • Updated: 2003-07-25
  • Resolved: 2003-07-25
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Related Reports
Relates :  
Relates :  
Relates :  
Description

Name: rmT116609			Date: 12/09/2002


FULL PRODUCT VERSION :
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)

FULL OPERATING SYSTEM VERSION :Windows 2000 WorkStation, SP2

ADDITIONAL OPERATING SYSTEMS :
Windows NT SP6 (server & Workstation), Windows XP Pro


A DESCRIPTION OF THE PROBLEM :
Start a java app that uses Clipboard.getContents() Using MicroSoft Excel and selecting 30 rows.

or go to www.cnn.com and select and copy the content

Set focus on the java app now Do a Clipboard.getContents()

Memory usage shoots way up and the app seems to hang - especially on XP or NT.


If I select data (huge Chunks say from a word document or a text file, no such problems.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Start a java app that uses Clipboard.getContents() Using MicroSoft Excel and selecting 30 rows.
Set focus on the java app now Do a Clipboard.getContents()

Memory usage shoots way up and the app seems to hang - especially on XP or NT.



EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected: System should not appear to hang

Actual : On NT & XP, took about 2 minutes before the java app responded.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.datatransfer.Clipboard;
import java.awt.Toolkit;
import java.lang.System;
import java.awt.datatransfer.Transferable;
import javax.swing.JOptionPane;

public class test {

	public test() {
	}
	
	public static void main(String[] args) throws Exception  {
		Clipboard cp = Toolkit.getDefaultToolkit().getSystemClipboard();
		Transferable	newData = cp.getContents(cp);
		JOptionPane.showMessageDialog(null, "Press here to continue");
		newData = cp.getContents(null);
		newData = null;
		cp = null;
		JOptionPane.showMessageDialog(null, "Press here to exit");
		System.exit(0);
			
	}
}
---------- END SOURCE ----------
(Review ID: 178739) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b13
2004-08-24

EVALUATION Name: agR10216 Date: 12/10/2002 The problem is reproducible on any platform. Clipboard.getContents() fetches clipboard data in all provided formats for which mapping to the corresponding data flavor in the default flavor map exists. So if there are a lot of formats in which clipboard data are to be fetched and the data are big enough, a lot of memory is consumed with the fetched data in different formats. I think, it was a design decision for Clipboard.getContents() to return a self-sufficient Transferable that is independent of the system clipboard contents later on. We should consider implementation possibility of a new API that allows to fetch current system clipboard data in the one specified data flavor, without prefetching data in several clipboard formats. ###@###.### 2002-12-10 ====================================================================== Name: agR10216 Date: 06/27/2003 This problem was fixed along with the RFE 4287795 (Would like Clipboard.isDataFlavorSupported() method). ###@###.### 2003-06-27 ======================================================================
2003-06-27

WORK AROUND Name: agR10216 Date: 12/10/2002 Comment some mappings between native clipboard formats and Java data flavors in the file jre/lib/flavormap.properties. For example, if you want to paste into your Java application a large Microsoft Excel table, copied to the system clipboard, as a text, you should commemt all lines except that contains mapping for the 'UNICODE TEXT' format. ###@###.### 2002-12-10 ====================================================================== Name: agR10216 Date: 12/10/2002 Also you can correct mappings between native clipboard formats and Java data flavors from your Java program. Since image data typically require a lot of memory, you can refuse to fetch clipboard data in the image formats. It is shown in the following code. FlavorMap fm = SystemFlavorMap.getDefaultFlavorMap(); if (fm instanceof SystemFlavorMap) { SystemFlavorMap sfm = (SystemFlavorMap)fm; List ln = sfm.getNativesForFlavor(DataFlavor.imageFlavor); DataFlavor[] flavors = new DataFlavor[0]; for (Iterator it = ln.iterator(); it.hasNext();) { sfm.setFlavorsForNative((String)it.next(), flavors); } } ###@###.### 2002-12-10 ======================================================================
2002-12-10