B4J Question SONGenerator Java Heap Space Out of Memory

Discussion in 'B4J Questions' started by rwblinn, Jan 17, 2015.

  1. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi,

    using the JSONGenerator in a Timer_Tick causes after running several hours a Java Heap Space Out of Memory Error.

    Any hints how this can be resolved appreciated.

    Code Snippets
    Code:
    Private Sub ScanTimer_Tick
    ...
        loadchart_event(
    Null)
    ...
    End Sub

    Code:
    ' Create google line chart on the webpage
    Sub loadchart_event(Params As Map)
        
    Dim cols As List
        cols.Initialize
        
    Dim rows As List
        rows.Initialize
        
    Dim options As Map
        options.Initialize
        
    '
        CreateLineChartData(cols, rows)
        CreateLineChartOptions(options)
        
    '   
        Dim jg As JSONGenerator
        jg.Initialize(CreateMap(
    "data": CreateMap ("cols": cols, "rows": rows), "options": options))
        ws.RunFunction(
    "drawCharts"Array As String(jg.ToString))
    End Sub
    B4J Error Log
    Code:
    java.lang.RuntimeException: java.lang.OutOfMemoryError: Java heap space
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    114)
        at anywheresoftware.b4a.BA$
    3.run(BA.java:178)
        at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:
    30)
        at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:
    26)
        at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:
    195)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:
    511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:
    266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:
    1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:
    617)
        at java.lang.Thread.run(
    Thread.java:744)
    Caused by: java.lang.OutOfMemoryError: Java heap space
        at org.json.JSONObject.<init>(JSONObject.java:
    112)
        at anywheresoftware.b4j.objects.collections.JSONParser$
    JSONGenerator.convertMapToJO(JSONParser.java:168)
        at anywheresoftware.b4j.objects.collections.JSONParser$
    JSONGenerator.convertListToJA(JSONParser.java:201)
        at anywheresoftware.b4j.objects.collections.JSONParser$
    JSONGenerator.convertMapToJO(JSONParser.java:179)
        at anywheresoftware.b4j.objects.collections.JSONParser$
    JSONGenerator.convertListToJA(JSONParser.java:201)
        at anywheresoftware.b4j.objects.collections.JSONParser$
    JSONGenerator.convertMapToJO(JSONParser.java:179)
        at anywheresoftware.b4j.objects.collections.JSONParser$
    JSONGenerator.convertMapToJO(JSONParser.java:173)
        at anywheresoftware.b4j.objects.collections.JSONParser$
    JSONGenerator.Initialize(JSONParser.java:132)
        at rwblinn.webtemp.webtemp._loadchart_event(webtemp.java:
    338)
        at rwblinn.webtemp.webtemp._scantimer_tick(webtemp.java:
    446)
        at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
    43)
        at java.lang.reflect.Method.invoke(Method.java:
    483)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    93)
        ... 
    9 more
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Can you upload this project?
     
  3. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi Erel,

    pls download here.

    Appreciated.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    There are three projects there. Which one is the problematic one? How can I reproduce it?
     
  5. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi Erel,

    it is with all 3. To reproduce it requires TinkerForge components. Let me see if I can make a version with simulates the TinkerForge components and then come back to you.
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    The error happened in Release mode, right?
     
  7. rwblinn

    rwblinn Well-Known Member Licensed User

    That is correct -- might be (but not sure) an issue with the JSONGenerator not releasing memory after being defined and initialized over and over in the sub:
    Code:
    Dim jg As JSONGenerator
    jg.Initialize(CreateMap(
    "data": CreateMap ("cols": cols, "rows": rows), "options": options))
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Try to reproduce it with a very fast timer.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice