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 9195101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:33:31+00:00 2026-06-17T21:33:31+00:00

I am working on a small java network program for instant messages using sockets.

  • 0

I am working on a small java network program for instant messages using sockets. In the application the messages are read using the DataOutputStream's readUTF() method, which return a String object. So every time a new message is arrived or sent a new String object is created in the memory, which in turn consumes memory. After a long time of communication there are several String objects in the memory.

So is there any way I can avoid this or I should try some other way of recieving messages. I am very new to Java network programming and its concepts.
Thanks.
I have a very bad coding style still I will try to make the question clear.

String recievedMessage = dataInputStream.readUTF();
String messageType = recievedMessage.substring(0, recievedMessage.indexOf("##"));
String message = recievedMessage.substring(recievedMessage.indexOf("##") + 2, recievedMessage.indexOf("$$"));

After this the message object is inserted in a JTextPane using a StyledDocument.

  • 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-17T21:33:32+00:00Added an answer on June 17, 2026 at 9:33 pm

    This is not specific to network programming: creating transient strings costs virtually nothing and they are efficiently garbage-collected. The only point where you’d start having issues would be if you retained the entire conversation transcripts in RAM. If you do need to save the transcripts, just forward all the messages to a file, without RAM retention.

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

Sidebar

Related Questions

I'm am currently working on a program in java which requires adding a small
I am currently working on a small desktop Java application which will track various
I am working on a small Java EE web application. The problem I have
I just started working on upgrading a small component in a distributed java application.
I'm working on a small application in Java that takes a directory structure and
I am working on a small webapp for fun, using just Java Servlets at
My small Java program is trying to darken a png image. It's working fine
I'm currently maintaining a small-medium sized java web application (using only plain JSPs/Servlets) that
I am currently working on a small project using RESTlet on Google App Engine/Java.
I'm working on a small java game which is a sort of clone of

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.