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

  • SEARCH
  • Home
  • 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 7951165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:28:47+00:00 2026-06-04T02:28:47+00:00

I’m using java to build a socket server. I’m logging lots of actions which

  • 0

I’m using java to build a socket server.

I’m logging lots of actions which are happening during the server run,
and beside each log line I’m writing the current free memory in the JVM using the:

Runtime.getRuntime().freeMemory()

as I can see in my log, I don’t have lots of free memory (around 14-15 MB).

I run this socket server on a freeBSD server with root access.

I really want to tune up the memory allocated to my JVM but I don’t really know how, and I’m pretty new to freeBSD and linux in general.

  • 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-04T02:28:49+00:00Added an answer on June 4, 2026 at 2:28 am

    You assumption about how memory works ( especially Garbage Collection ) in Java is flawed.

    Runtime.getRuntime().freeMemory().

    That call only shows “free” memory on the JVM heap, which is allocated with the -Xms and -Xmx command line arguments to java. Or in some startup script if you are using an app server.

    Why what you are trying to do is a waste of time

    See this answer to this question why!

    The Garbage Collector in Java ( which controls free memory ) isn’t tuned to keep as much memory free as possible, it is tuned for a balance of performance and responsiveness. It only frees memory on demand, there is no benefit in having max free memory and lots of downsides to trying to do so.

    This causes objects that aren’t referenced anymore to hang around “using memory” until the memory they occupy is actually needed. This is actually optimal because prematurely removing them would cause performance degradation of the running code.

    Removing them very quickly only when memory needs to be freed is the goal of the Garbage Collector not trying to keep as much memory free as possible.

    You should never have to call System.gc() in a correctly implemented Java program.

    Java HotSpot includes three different collectors. The serial
    collection uses a single thread for GC and is best suited for single
    processor machines with data sets smaller than 100 Mbytes. The
    parallel performs minor collections in parallel. It is ideally suited
    for medium to large datasets running on multi-threaded or
    multi-processor hardware. The concurrent collector has been optimized
    to garbage collection pauses short when response time is more
    important than throughput. This mode does not normally provide any
    benefit on a single-core machine.

    To avoid OutOfMemoryExceptions

    1. Set -Xmx to as large a setting as you can afford on your server. Set -Xms to the minimum size of block of memory you think is nominal. Too small is worse than too big.

    2. Don’t leak references.

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

Sidebar

Related Questions

I would like to run a str_replace or preg_replace which looks for certain words
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.