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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:46:09+00:00 2026-06-01T22:46:09+00:00

I’ve searched for this but can’t seem to find a straight answer for this.

  • 0

I’ve searched for this but can’t seem to find a straight answer for this.

Basically I have some code that creates a copy of an array(using Arrays.copyOf to create int[]), and it does some work and either outputs the results or sends the Arrays.copyOf to a queue for further processing.

If I change the copyof my results are no longer correct so I think I need it but I’m wondering if there’s something I can do after its done because, as per my memory profiling, its taking up all my memory and garbage collecting helps but it just builds up again. I’m really not sure if this will help but I wanted to test to see if my program functions as it did with a smaller memory footprint if I somehow delete the int[] after submitting it to a queue.

I’m new to Java so if this logic is totally flawed, is there another way to achieve the same result? Bottom line is I’m creating a new array its being used a bit but lingers around when no longer needed(it takes 15G of my max memory, then I believe garbage collector comes in and reduces it but it shots back to max within a few seconds again). Maybe can I set the variable to null or something once I’m sure its not needed(the objects I’m copying are quite large)?

Here’s some code just to show what I mean(its kind of crappy but hopefully it lets you understand how its setup in the code, all this is within a multithreaded callable):

 while(!queue.isEmpty()) {
                int[] data_list = Arrays.copyOf(current.list, current.list.length);

                    if (things work) {
                        Sysout("print results");
                    } else if (current.k > 0) {
                        queue.add(new Queue(data_list)); 

                    }
                }
            }
  • 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-01T22:46:10+00:00Added an answer on June 1, 2026 at 10:46 pm

    In general, the thing to do here is “trust that the garbage collector knows what it’s doing.” The JVM is very good at figuring out when objects aren’t needed any more, especially e.g. if it can prove that an object doesn’t “escape” the method where it was created.

    Java doesn’t even provide a way to delete the memory being used by an object, except eliminating all references to it — which is exactly what you’re doing.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.