• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

java.lang.OutOfMemoryException:java heap space problem

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to process a large file and I am using string manipulations to the large extent.
I am getting "java.lang.OutOfMemoryException:java heap space problem" exception while processing a large data file.While for small files it works properly.

I have tried to increase the heap space , but no use

The same code works in unix for large files also..but not on windows...

I have also tried to prevent memory leaks by using String a=new String(b.subString(10)); etc for sunstring and replaceAll methods..

Please advise.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure how what you did there is supposed to help with memory leaks, but that's a different issue.

Without knowing anything about what you're doing or how, it'll be impossible to help.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David, since substring uses the original string internally, it retains a reference and prevents it being garbage collected. therefore if you parse a file line by line and cut the first word you still end up holding the whole file in memory.

Have you considered that you might just not have enough memory? eg How large is the file, how large is the expected result and how much memory are you providing? Can you be sure of these numbers?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

David O'Meara wrote:David, since substring uses the original string internally, it retains a reference and prevents it being garbage collected. therefore if you parse a file line by line and cut the first word you still end up holding the whole file in memory.


Ah, gotcha; thanks!
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and how much heap are you providing? ie what memory settings do you specify?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

David Newton wrote:Ah, gotcha; thanks!


I only learnt it a week or two ago...
 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic