Git Product home page Git Product logo

Comments (8)

GoogleCodeExporter avatar GoogleCodeExporter commented on June 11, 2024
You don't have to convert the stream into a String to pass it to JSONParser.
JSONParser accepts a Reader as its parameter.

Could you comment out the last line and then test it again?

return (JSONObject) jsonParser.parse(sb.toString());

And could you help to print out the result of sb.toString() and post it here 
before
passing it to JSONParser? That will be very helpful to analyze this issue.

Thanks.

Original comment by [email protected] on 28 Nov 2009 at 4:10

from json-simple.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 11, 2024
That didn't help, unfortunately. I also can't log the StringBuilder contents, 
because
adb just cuts off strings which are too long to log, but I've attached the JSON 
data
served by our web service.

It's not a problem with that specific document though. I've seen this happening 
all
over the place.

Original comment by [email protected] on 30 Nov 2009 at 9:20

Attachments:

from json-simple.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 11, 2024
Thanks a lot for the data.
It's strange that from my initial testing (using a very simple method), nothing 
seems
to be special.(Local JDK is 1.6. What is the version of the JDK/JRE in your 
environment?)

Here's the code:
{{{{
public static void main(String[] args) throws Exception{
        long t = System.currentTimeMillis();
        long m = Runtime.getRuntime().freeMemory();
    Object obj = JSONValue.parse(new FileReader("reviews.json"));
        long delta = System.currentTimeMillis() - t;
        long deltaM = m - Runtime.getRuntime().freeMemory();
        System.out.println(delta + "ms");
        System.out.println(deltaM/1024 + "K");
    System.out.println(obj);
}
}}}}

Here's the result:
79ms
537K
(The resulting JSON text)

I also used YourKit 7.5 to do memory profiling and got the following data:
Overall objects:
All live objects: 13,025 Shallow size: 1,098,824 bytes Retained size: 1,098,824 
bytes

Dominant objects:
char[] 2,902 objects, shallow size: 429,656
java.lang.String 3,132 objects, shallow size: 75,168

Thanks.

Original comment by [email protected] on 30 Nov 2009 at 11:07

from json-simple.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 11, 2024
I just replaced JSON simple with the reference JSON implementation from json.org
(which is shipped with Android), and it doesn't suffer from this problem.

There must be something leaking (and massively so -- considering it turns a 40k 
JSON
string into 12 megabytes), in JSONParser.parse().

However, to not waste your time:
It may well be that this is in fact something related to Apache Harmony, the
open-source Java implementation that powers Android. I have been running into
problems on Android several times now where Harmony turned out to be the source 
of
the problem (it's scary sometimes how buggy it can be at its core 
infrastructure).

I guess the best thing to do would be:
Write a simple test case which parses a JSON file, and profile it both using 
the Sun
JVM and the Harmony JVM.

The Android profiler unfortunately isn't detailed enough to tell me exactly 
which
method/object is actually consuming so much memory, but it shows me 10-12MB 
worth of
character data being allocated during a parse(), so it must be something 
related to
reading/buffering character data.

Original comment by [email protected] on 30 Nov 2009 at 11:11

from json-simple.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 11, 2024
Thanks a lot for your information.
I'll test it in Harmony JVM.

Original comment by [email protected] on 30 Nov 2009 at 11:20

from json-simple.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 11, 2024
One solution would be to just use the lexer. I've posted some code to Fang that 
extends the lexer and uses it 
similar to the XMLStreamReader in Java 1.6, effectivly saving lots of RAM when 
processing large amounts of 
JSON. Let me know and I'll post it again.

Original comment by [email protected] on 30 Nov 2009 at 4:59

from json-simple.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 11, 2024
Hi,

The following patch should fix the OutOfMemory problem. At least, it works for 
my JVM.


--- a/src/org/json/simple/parser/Yylex.java
+++ b/src/org/json/simple/parser/Yylex.java
@@ -577,7 +577,7 @@ int getPosition(){
           }
         case 25: break;
         case 4:
-          { sb.delete(0, sb.length());yybegin(STRING_BEGIN);
+          {  sb = null; sb = new StringBuffer(); yybegin(STRING_BEGIN);
           }
         case 26: break;
         case 16:

Glen

Original comment by [email protected] on 16 May 2012 at 7:25

from json-simple.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 11, 2024
Hi glen.tw,

I've applied it to the code. Thanks a lot for your contribution.
Unfortunately I cannot validate it on Android Phone because I don't have one. 
Can any of you help validate it and let me know the result?

Thanks,
Yidong. 

Original comment by [email protected] on 16 May 2012 at 1:56

  • Changed state: Fixed

from json-simple.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.