Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Infinity job to refresh UI leads to memory leak(Display + asyncExec + infinity loop + memory leak)
Infinity job to refresh UI leads to memory leak [message #534462] Wed, 19 May 2010 09:39 Go to next message
Andrew  is currently offline Andrew
Messages: 43
Registered: December 2009
Member
Hello, I need to update my UI with data from server.
In order to do that I'm using a job:
Job j = new Job("update job") {
// ....
}

When job is finished with status OK I try to update UI with asyncExec:
 Display.getDefault().asyncExec(new Runnable() {
	// update UI
}

Then If I try to do something like that:
boolean ok = true;
  while(ok) {
    try {
              Thread.sleep(10);
    }
    catch (InterruptedException e) {
         e.printStackTrace();
    }   
   j.scheduler();
}

I'v got a memory leak. Analizing memory heap showed that org.eclipse.swt.widgets.RunnableLock object's are accumulate and cause Out Of Memory. If I'm using
 Display.getDefault().syncExec(new Runnable() {
	// update UI
}

then all is fine. Can you explain me what's the problem with asyncExec ?
Re: Infinity job to refresh UI leads to memory leak [message #534709 is a reply to message #534462] Thu, 20 May 2010 05:29 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.
Messages: 621
Registered: July 2009
Senior Member
On 19/05/10 3:09 PM, Andrew wrote:
> Hello, I need to update my UI with data from server. In order to do that
> I'm using a job:
> Job j = new Job("update job") {
> // ....
> }
>


Why can't you use UIJob?

- Prakash
Platform UI Team, IBM

www.eclipse-tips.com
Re: Infinity job to refresh UI leads to memory leak [message #534722 is a reply to message #534709] Thu, 20 May 2010 07:06 Go to previous messageGo to next message
Andrew  is currently offline Andrew
Messages: 43
Registered: December 2009
Member
I can't use UIJob, coz getting data from server is long time operation and it will make the UI unresponsive until it completes.
Re: Infinity job to refresh UI leads to memory leak [message #534856 is a reply to message #534462] Thu, 20 May 2010 13:54 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Andrew wrote:
>
> Then If I try to do something like that:
>
> boolean ok = true;
> while(ok) {
> try {
> Thread.sleep(10);
> }
> catch (InterruptedException e) {
> e.printStackTrace();
> } j.scheduler();
> }

Where is the above code? In the asyncExec(*)?

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Infinity job to refresh UI leads to memory leak [message #534923 is a reply to message #534856] Thu, 20 May 2010 16:14 Go to previous messageGo to next message
Andrew  is currently offline Andrew
Messages: 43
Registered: December 2009
Member
No, this code in a button handler which start infinity update job.
Re: Infinity job to refresh UI leads to memory leak [message #534979 is a reply to message #534923] Thu, 20 May 2010 21:04 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Andrew wrote:
> No, this code in a button handler which start infinity update job.
>

boolean ok = true;
while(ok) {
try {
Thread.sleep(10);
}
catch (InterruptedException e) {
e.printStackTrace();
} j.scheduler();
}


This code can't be on the UI thread, it will block it. I presume a
button handler is an SWT Listener or SelectionListener.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Infinity job to refresh UI leads to memory leak [message #535009 is a reply to message #534979] Fri, 21 May 2010 03:15 Go to previous messageGo to next message
Andrew  is currently offline Andrew
Messages: 43
Registered: December 2009
Member
Yes, it will. But is the problem in it ? I need this loop only for emulating user update button click (this loop only for quick reproduce problem). Without this loop i've got Out Of Memory too after many times update button clicking (update button start update job which load data from server and update UI)...

[Updated on: Fri, 21 May 2010 03:17]

Report message to a moderator

Re: Infinity job to refresh UI leads to memory leak [message #535152 is a reply to message #535009] Fri, 21 May 2010 12:33 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Andrew wrote:
> Yes, it will. But is the problem in it ? I need this loop only for
> emulating user update button click (this loop only for quick reproduce
> problem). Without this loop i've got Out Of Memory too after many times
> update button clicking...

Maybe I misunderstand, but basically you need to do short, UI related
work on the UI thread, and whatever other work you are doing on your
second thread. In your real app, you are getting to the end of a Job
and then posting a display,asyncExec(*) right?

You cannot have that loop you posted in the UI thread, even for an
example, or the UI thread will never process any more asyncExecs(*),
since they're done in the display.readAndDispatch() method and your
loop prevents it from returning to that method.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Previous Topic:Force loading of a stacked view
Next Topic:Custom Label Provider not firing for org.eclipse.core.resources.IFile
Goto Forum:
  


Current Time: Mon Sep 15 09:30:04 GMT 2014

Powered by FUDForum. Page generated in 1.54455 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software