• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Strange java.lang.OutOfMemoryError

 
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

See stack trace and code below. I'm working with a pool of threads that simulates bank transactions, and I'm having a strange problem. I'm running out of memory, but am really not instantiating THAT many objects. Maybe I have some kind of memory leak or am doing something silly that I'm overlooking? Could someone point me in the right direction? As usual, thanks in advance!


*edited
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i-- ?
 
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
Actually, you are creating a whole hell of a lot of accounts here:



That "i--" means you subtract 1 from i each time through the loop, and keep going as long as i is less then 1000. Well, i will start at 0, and become -1, then -2, then -3, and so on until you get to the largest possible negative int, which is a little over 2 billion. And that's a lot! At that point, subtracting 1 from the largest negative int will underflow and give you the largest possible int, which is larger than 1000, so the iteration stops.

I'm thinking you want a "i++" there instead.
 
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
Damn, Christophe beat me by one minute!
 
Bartender
Posts: 2908
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alas !

Its not the Error that is strange but the program that is.
 
James Brooks
Gunslinger
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

salvin francis wrote:Alas !

Its not the Error that is strange but the program that is.



D'oh!!! Indeed! It was originally a countdown loop, which I modified to count up, and guess I forgot to change to ++. Thanks!
 
rubbery bacon. rubbery tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic