Hi CEHJ,
The only way I use it is like this:
invokeLater() {
new Thread() {
public void run() {
... whatever ...
{
{
);
so the Thread instance should only have one reference?
Main Topics
Browse All TopicsHi,
In many UI frameworks we have some way of synchronizing a job back on the main UI thread, like:
Application.invokeLater(Ru
for instance if we wanted to download an image in a background thread, and display it when it's done downloading.
Most of these frameworks want a Runnable instance - on some systems I've noticed that the Runnable instance never terminates (even though their run() method has been exited), so I started using Thread instead:
invokeLater(new Thread(..));
instead of:
invokeLater(new Runnable(...));
now I'm on yet another UI framework for a different project, that also asks for Runnable instances. As a test, I gave it a Thread instance, and while the thread does terminate, it leaks a lot of memory on every call. If I pass it a Runnable, it works perfect, no leaks.
I'm just wondering what difference is there in passing these systems:
invokeLater(new Thread() { public void run() { ... } } );
vs
invokeLater(new Runnable() { public void run() { ... } } );
I expected them to behave the same way?
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Ok I've attached my full example. The platform is google's Android. Their docs do say to pass Runnable, and no memory leaks happen when I use Runnable, but I'm just curious as to why Thread causes the memory leak, if there's some intrinsic difference between the two. May just be a platform thing, but still curious, thanks:
I'm just wondering what difference is there in passing these systems:
invokeLater(new Thread() { public void run() { ... } } );
vs
invokeLater(new Runnable() { public void run() { ... } } );
I expected them to behave the same way?
Technically they would both behave the same way.
Though using a Runnable is advisable as its just an interface and thus has no overhead.
Any leak would be a result of the Thread object overhead
That's the exact code I'm running. I'm just post()'ing an empty Thread or an empty Runnable. I see memory allocation increase by 10k each time the testit() function is called, until the phone crashes with an out of memory exception. Runnable works ok, Thread leaks though. Is that the other code you're asking for (sorry I am misunderstaning).
Yeah I don't understand why it should leak like this,
Thanks
Business Accounts
Answer for Membership
by: CEHJPosted on 2009-10-14 at 11:32:31ID: 25573550
If you're passing it Thread instead of Runnable, you need to ensure you're not holding references to it that are preventing GC