DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Python Variables Declaration
  • Techniques You Should Know as a Kafka Streams Developer
  • Handling Virtual Threads
  • Java and Low Latency

Trending

  • Freedom to Code on Low-Code Platforms
  • Exploring the Evolution and Impact of Computer Networks
  • A Better Web3 Experience: Account Abstraction From Flow (Part 1)
  • Supercharge Your Communication With Twilio and Ballerina
  1. DZone
  2. Coding
  3. Java
  4. Java - OOM Example

Java - OOM Example

Navaneethakrishnan Ramakrishnan user avatar by
Navaneethakrishnan Ramakrishnan
·
Aug. 23, 13 · Interview
Like (0)
Save
Tweet
Share
2.58K Views

Join the DZone community and get the full member experience.

Join For Free

i did an experiment today and wrote a code snippet that would ultimately fail with an outofmemory (oom) error. there are 2 variations in what i did.

1. class with explicit system.gc() call

2. class without explicit system.gc() call

as expected, both the executions fail with oom. but what is interesting is the free memory pattern generated by both. please refer to the attachment for details and share your thoughts/comments on this.

here is the code.


import java.util.arraylist;
import java.util.list;

public class javaoom {

   public static void main(string[] args) {
     system.out.println("initial freememory: "+runtime.getruntime().freememory()/(1024*1024));
     oom1();

   }
   
   private static void oom1() {
     list<string> mylist = new arraylist<string>();
     for (long i=0; ; i++) {
       mylist.add(long.valueof(i).tostring());
       if (i%100000==0) {
         //system.gc();
         system.out.println("i: "+i+", freememory: "+runtime.getruntime().freememory()/(1024*1024));
       }
     }
   }

}



Java (programming language) Snippet (programming) Execution (computing) Memory (storage engine)

Opinions expressed by DZone contributors are their own.

Related

  • Python Variables Declaration
  • Techniques You Should Know as a Kafka Streams Developer
  • Handling Virtual Threads
  • Java and Low Latency

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: