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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:36:13+00:00 2026-05-22T21:36:13+00:00

I am working on an OutOfMemory exception generated when a really large JSONObject is

  • 0

I am working on an OutOfMemory exception generated when a really large JSONObject is created but never garbage collected by Android’s framework. On each subsequent update the memory leak just gets bigger and bigger till I run out of memory. We have a large data structure that changes over time and on each update we send the whole datastructure to the client and refresh it. I know that is not the best way to do it, but changing the whole infrastructure just for Mobile is going to take some time and convincing to do.

As for the here and now, when an Object goes out of scope in Java, it should be marked as available to be garbage collected. I am using the Eclipse MAT tool to do my memory analysis and according to the tool, each String I parse out of the JSONObject has a link back to the original JSONObject. A fix I have is I created a remove function where I iterate through each of the JSONObjects keys and call JSONObject.remove(key) after I am done parsing, that works like a charm and all memory is collected. However, why do I need to do that? I should not have to do that to an out of scope object. Any ideas?

Thanks in advance!

Jared Sheehan

  • 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-05-22T21:36:14+00:00Added an answer on May 22, 2026 at 9:36 pm

    Maybe it’s best to convert your JSON response into a POJO as soon as you receive it.
    The Jackson JSON parser will do that for you in two lines of code and can also turn it back into your JSON Object if you ever need to do that.

    Jackson is very fast (they claim the fastest of all the parsers) so you won’t take much of a performance hit.

    Check out this tutorial on their website.

    from the tutorial, you can take this simple JSON object:

    {
        "name":
        {
            "first":"Joe",
            "last":"Sixpack"
        },
        "gender":"MALE",
        "verified":false,
        "userImage":"Rm9vYmFyIQ=="
    }
    

    and parse it into your own object with this code:

    ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
    User user = mapper.readValue(new File("user.json"), User.class);
    

    Just so you know, I also had issues with memory retention in my latest Android project and eventually gave up on using JSON altogether.

    Good luck!

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

Sidebar

Related Questions

I stumbled upon an OutOfMemory-Exception when working with lots of pictures (sequentially, not in
Working with a SqlCommand in C# I've created a query that contains a IN
Working with an API that can handle multiple connections (i.e. sessions), each of these
Working with dates in ruby and rails on windows, I'm having problems with pre-epoch
Working on a project at the moment and we have to implement soft deletion
Working on a somewhat complex page for configuring customers at work. The setup is
Working on a project that parses a log of events, and then updates a
Working with python interactively, it's sometimes necessary to display a result which is some
Working in Eclipse on a Dynamic Web Project (using Tomcat (v5.5) as the app
Working with TCL and I'd like to implement something like the Strategy Pattern .

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.