• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

memory problems,

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys
i am having a memory problem.
this is the code:
Runtime runtime = Runtime.getRuntime();
public static final int IMAGE_MEMORY_NEEDED = 3 * 1024 * 1024;
int [] tmpArray = null;
tmpArray = new int[IMAGE_MEMORY_NEEDED];
tmpArray[0] = 1;
tmpArray[IMAGE_MEMORY_NEEDED - 1] = 1;
tmpArray = null;
tmpArray = new int[0];
runtime.gc();
Thread.yield();
...
i need to free the memory, but it
nothing is working, it's not freeing the memory!?
why is that, the gc is not collecting
any ideas!?
Thanks, omar
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What makes you think the GC is not working?

Note that Sun's JVMs never return memory to the OS; free memory is returned to the Java heap, but your "task manager" or other OS-dependent tool will still show the memory being allocated to the process.
 
omar bili
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Ernest for ur reply
is there a way to return the memory to windows?
Best, Omar
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. The heap of Sun's JVMs will grow, but won't shrink, in size. If this is important for your application, there might be other (commercial) JVMs that don't have this property; you'd have to do some Googling and check it out.
 
You didn't tell me he was so big. Unlike this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic