Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8414839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:16:14+00:00 2026-06-10T01:16:14+00:00

We are doing a memory test of an application on centos. What we notice

  • 0

We are doing a memory test of an application on centos. What we notice is that top shows the memory keep growing which we suspect due to the JVM requiring extra space. In addition in the application codes we have this few lines at the end. What we notice this also showing that the used memory and heap size also keep growing at first it was in tens of megabytess and now is in few hundreds of megabytess value.

Runtime runtime = Runtime.getRuntime();
long memory = runtime.totalMemory() - runtime.freeMemory();
System.out.println("\n\nUsed memory is bytes: " + memory);
//Print the jvm heap size.
long heapSize = runtime.totalMemory();
System.out.println("\n\nHeap Size = " + heapSize);

On the other hand we use this command /usr/java/jdk1.7.0_03/bin/jstat -gcutil 22805 and notice that after some time both the S0 and S1 is being cleaned to zero? Does this interpretation gives some indication of memory problem or this is normal behavior of java?

Below is the skeleton of our codes. From statement 6 I have a big loop of while then in it I got further many queries could this be the culprit?

try{

         try{ //inner try for each complete message read from the socket connection

//lots of inner queries run based on some logics of if else etc


//sample query of opening and closing both statement and resultsets.

Statement stmt1 = null;
stmt1 = dbconn.createStatement();
String selectQuery1  = "Select query";
ResultSet rs1 = stmt1 .executeQuery(selectQuery1);
while(rs1.next()) {
//process here

}
try{
  if (rs1 != null ){
        rs1.close();
  }
  if (stmt1!= null ){
        stmt1.close()
  }
}
catch(SQLException ex){
  ex.printStackTrace(System.out);
}

          Statement stmt6 = null;
          stmt6 = dbconn.createStatement(); 

String selectQuery3 = "Select query....";
ResultSet rs3 = stmt6.executeQuery(selectQuery3);

          while(rs3.next()) {
              var1= rs3.getInt("value1");
    var2 = rs3.getString("value2");
    if(var2.equals("POINT"){
                  Statement stmt7 = null;
                  stmt7 = dbconn.createStatement();
        String selectQuery4= "select query ... ";
        ResultSet rs4 = stmt7.executeQuery(selectQuery4);
        if(rs4.next()){
    Statement stmt8 = null;
                        stmt8 = dbconn.createStatement();
                        if(lastID>0){

                             String updateQuery2 = "update query .......";
                             count = stmt8.executeUpdate(updateQuery2);
                             String insertQuery2 = "insert query .....";
                             count = stmt8.executeUpdate(insertQuery2);
                             String selectLast1 = "SELECT last_insert_id()";
         ResultSet rs5 = stmt8.executeQuery(selectLast1);
         if(rs5.next()){
                 gFAlertIDOut=rs5.getInt(1);
         gFOutID = lGFID;
         } 
                             String insertQuery3 = "insert query .....";
                             count = stmt8.executeUpdate(insertQuery3);
                             String selectLast2 = "SELECT last_insert_id()";
         rs5 = stmt8.executeQuery(selectLast2);
         if(rs5.next()){
                 gFAlertIDIn=rs5.getInt(1);
         gFIntID = lGFID;
         } 
                             try{
                       if (rs5 != null ){
                           rs5.close();
                      }
                      if (stmt8!= null ){
                         stmt8.close();
                      }
                  }
                  catch(SQLException ex){
                   ex.printStackTrace(System.out);
                  }   

                        }
                        else{

                       }                                 
                  }
                  try{
            if (rs4 != null ){
                rs4.close();
        }
        if (stmt7!= null ){
               stmt7.close();
        }
       }
       catch(SQLException ex){
          ex.printStackTrace(System.out);
       }   

              }
              else{
                  Statement stmt7 = null;
                  stmt7 = dbconn.createStatement();
        String selectQuery4= "select query ... ";
        ResultSet rs4 = stmt7.executeQuery(selectQuery4);
        if(rs4.next()){



                  }

                  try{
            if (rs4 != null ){
                rs4.close();
        }
        if (stmt7!= null ){
               stmt7.close();
        }
       }
       catch(SQLException ex){
          ex.printStackTrace(System.out);
       }   

              }


          }
          try{
    if (rs3 != null ){
       rs3.close();
    }
    if (stmt6!= null ){
       stmt6.close();
    }
}
catch(SQLException ex){
      ex.printStackTrace(System.out);
 }   

dbconn.commit();
}
catch (SQLException ex) { 
  try {    
    dbconn.rollback();  
  } 
  catch (Exception rollback){    
    rollback.printStackTrace(System.out);
  } 
}
catch (Exception e){
 try{    
        dbconn.rollback();  
  } 
  catch (Exception rollback) {    
    rollback.printStackTrace(System.out);
  }
}
     }
     catch (SocketTimeoutException ex){ 
           ex.printStackTrace();
     }  
     catch (IOException ex) { 
           ex.printStackTrace();
     }  
     catch (Exception ex){  
                    ex.printStackTrace(System.out);
     }      
     finally{
        try {
    if ( dbconn != null ){ 
       dbconn.close();
                        }
        }
        catch(SQLException ex){
                    ex.printStackTrace();
        }
        try{ 
              if ( writer1 != null ){
        writer1.close();
    }

        }
        catch(IOException ex){
           ex.printStackTrace(System.out);
        }


     }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:16:15+00:00Added an answer on June 10, 2026 at 1:16 am

    Sounds like your application has a memory leak. It is not normal for Java’s memory usage to increase at a constant rate when performing a process which doesn’t require more memory over time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all. I'm doing a linked list exercise that involves dynamic memory allocation, pointers,
I've found that all of these scripts, while doing the same thing create memory
So I have this extremely memory-intensive Java application I'm building, which builds a tree
I am using HSQL in memory database for test purpose of my application and
I've created a ipad application and now I'm doing some test with Instruments to
I am doing in-memory image conversions between two frameworks (OpenSceneGraph and wxWidgets). Not wanting
I'm doing a little bit of memory profiling to my software and after running
Is there a more efficent way of doing this in terms of memory usage
We are using DevPartners boundchecker for detecting memory leak issues. It is doing a
My project requires me to allocate memory dynamically. What am I doing wrong? /*Setting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.