Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 12391 - Handling OutOfMemoryError
Summary: Handling OutOfMemoryError
Status: RESOLVED DUPLICATE of bug 12224
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Resources (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-Resources-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-03-27 16:15 EST by Ian Petersen CLA
Modified: 2002-09-27 09:46 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Petersen CLA 2002-03-27 16:15:47 EST
Build: 20020321

Description:
I developed a benchmark to determine how long it takes to do a plaintext search 
in Eclipse.  Effectively, my benchmark imports all of Eclipse as source, and 
then repeatedly searches for instances of the word 'for' in all available 
resources.  I can only do the search about 12 times before I get an error 
message telling me to go look in the log file for further details.  I did a 
system-wide search for this log file and found none.  After checking my 
benchmark code a few times, I performed the test manually and came up with the 
same results.  I lost track of how many searches it took to cause the error but 
I did eventually cause it.  

There are approximately 48,000 instances of 'for' in Eclipse.  The first few 
times I ran the search, it found all 48,000 and it seemed to run reasonably 
quickly.  The time that the search failed, it only found about 1,700 instances 
and the search ran very slowly.  I dismissed the error and tried the search 
again.  This time it found about 12,000 instances before failing the same way.  
I can't find a log file, or a core file, so I don't know what the exception 
was, and I don't have a stack trace.  The problem does seem to be repeatable, 
though.
Comment 1 Dani Megert CLA 2002-04-22 05:34:09 EDT
Possible reason which comes to mind: out of memory exception

Comment 2 Dani Megert CLA 2002-05-02 08:37:40 EDT
Could you provide the benchmark? Could my comment point into the right direction?

Comment 3 Tod Creasey CLA 2002-05-02 08:57:11 EDT
This is in the org.eclipse.benchmarks in ottcvs1://home/cvs/desktop in the 
class TextSearchBenchmark.

Here is the contents of the class. And yes I believe this was a result of an 
Out of Memory error as Search increases the siuze of the heap dramatically.


package org.eclipse.benchmarks.search;

import java.lang.reflect.Field;

import org.eclipse.benchmarks.*;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.search.internal.ui.text.TextSearchPage;
import org.eclipse.swt.widgets.*;

public class TextSearchBenchmark extends Benchmark {
	private static final int ITERATIONS = 25;
	
	private Shell shell;

	/**
	 * Constructor for TextSearchBenchmark.
	 * @param testName
	 */
	public TextSearchBenchmark(String testName) {
		super(testName);
	}

	public void testTextSearch() throws Exception {
		Field searchPattern = TextSearchPage.class.getDeclaredField
("fPattern");
		Field fileExtensions = TextSearchPage.class.getDeclaredField
("fExtensions");
		
		searchPattern.setAccessible(true);
		fileExtensions.setAccessible(true);
		
		Combo pattern;
		Combo extensions;
		
		TextSearchPage page = new TextSearchPage();
		SearchPageContainer container = new SearchPageContainer
(this.shell, new StructuredSelection(), page);
		
		container.setBlockOnOpen(false);
		container.open();
		
		pattern = (Combo)searchPattern.get(page);
		pattern.setText("for");
		
		extensions = (Combo)fileExtensions.get(page);
		extensions.setText("*.*");
		
		AggregateStopWatch watch = new AggregateStopWatch(ITERATIONS, 
1, new String[] {"Time to search for 'for'"});
		BenchmarkLogFile file = new BenchmarkLogFile();
		file.addWatch(watch, watch.getDefaultHeader("TextSearch", "Time 
to search all of Eclipse for instances of 'for'"));

		file.prepareForCrash();
		
		for(int i = 0; i < ITERATIONS; i++) {
			watch.startNewIteration();
			page.performAction();
			watch.stopIteration();
			this.flushEventQueue(this.shell.getDisplay());
			System.out.println(i + 1);
		}
		
		container.cancelPressed();
		
		file.writeAsCSVTo(this.log);
		file.normalShutDown();
//		MessageDialog.openInformation(this.shell, "Wait loop", "Look 
for some search results");
	}
	
	public void setUp() throws Exception {
		super.setUp();
		
		this.shell = this.fWorkbench.getActiveWorkbenchWindow().getShell
();
		IPluginModelBase[] models = BenchmarkPDEUtil.getAllModels();
		BenchmarkPDEUtil.importModels(models, true);
//		BenchmarkPDEUtil.importModels(models, 0, Math.min(5, 
models.length), true);
	}
}


Comment 4 Adam Kiezun CLA 2002-05-23 08:16:06 EDT
see bug 16731 
and bug 16732
(once these get fixed we can retry this scenario)
Comment 5 Adam Kiezun CLA 2002-05-23 08:25:07 EDT
nope, these 2 are not related
they are major , but show up only whan you close the search view, 
reopen, do search, close .... (basically, if you do search in a new view 
everytime)
sorry for confusion

i'm back to leak hunting...
Comment 6 Adam Kiezun CLA 2002-05-23 08:55:52 EDT
more findings

no leak in the following scenario:
1. text search
2. remove all search results

however, repeated search is a problem
because all previous searches are kept around
objects of class Search are heavy-weighted - they have handles to many things

so, repeated search, without clearing search results will eventually lead 
to OutOfMemory error
Comment 7 Dani Megert CLA 2002-07-25 09:08:58 EDT
Since the history is kept search will run out of memory at some point. When I
test it against 2.0 then an error dialog is shown which points you to the .log.
The .log contains the OutOfMemoryError. This can happen to *all* our operations
at some point: we normally don't catch OutOfMemoryError in our code to present a
special dialog.

This is a general platform issue: how do we handle out of memory and how is it
presented to the user. Currently he is most likely lost: the VM is already out
of memory and saving the workspace will fail. 
Core (along with Platform UI) should pre-allocate some memory, catch the
OutOfMemoryException if not headless show a dialog to the user saying we're out
of memory and then freeing the memory we allocated at the beginning, then save
and exit the workspace.

Moving to platform core for investigation of the general problem.
Comment 8 DJ Houghton CLA 2002-08-29 15:12:46 EDT
Old title: Internal Error after repeated search
Comment 9 DJ Houghton CLA 2002-09-27 09:46:19 EDT

*** This bug has been marked as a duplicate of 12224 ***