B4J Question Fine tuning of Garbage Collector?

vfafou

Well-Known Member
Licensed User
Longtime User
Hello!
My web socket server application with MySQL database connection pooling, seems that something needs about garbage collection (or there is a memory leak???).
The Java Visual VM shows the following data:

Morning (1):
B4X:
Live Threads: ~1120
Used Heap: ~850MB before GC, ~140MB after GC
Total Started Threads: ~1700

Evening (2):
B4X:
Live Threads: ~980
Used Heap: ~1.1GB before GC, ~210MB after GC
Total Started Threads: ~2300

Night (3):
B4X:
Live Threads: ~510
Used Heap: ~1.3GB before GC, ~250MB after GC
Total Started Threads: ~2900

Pressing the Perform (full) GC button, the night's data are (4):
B4X:
Live Threads: ~510
Used Heap: ~230MB
Total Started Threads: ~2900

Stopping and starting the server application after (4):
B4X:
Live Threads: ~226
Used Heap: ~880MB before GC, ~47MB after GC
Total Started Threads: ~247

I'm starting the server with:
B4X:
java -Xms2G -Xmx5G -XX:MaxPermSize=256m -XX:NewRatio=1 -XX:+UseConcMarkSweepGC -verbosegc -jar MyServer.jar

Note that after restarting, the live threads became ~226 instead of ~510.

All database connections are closed after using them.
The most "useless" threads seems that are websocket connections!

My server is a HP proliant with 4core XEON and 16GB RAM, with Ubuntu Linux OS.

Do you think that something goes wrong?

Thank you in advance!
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
I prefer to write it like this:
B4X:
Dim PSQL As SQL = Main.Pool.GetConnection
Try
 ...
Catch
 Log("error: "& LastException)
End Try
PSQL.Close

Note that you should expect to see live connections as the connection pool keeps some connections open. The question is whether the number grows without limits.

I don't see any error in your code.
 
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
Do you use Cursors with SQL? If yes, make sure they are all closed before calling SQL.close.
Hi jmon!
Yes, I use 3-4 cursors that I take care to close them after loop!
The only thing I've found reading my code, was a transaction without begin-successful. I don't know if this is the reason of remaining open connections...
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
I see an error in your code, but maybe not related to your memory leak. In all your samples, the PSQL variable is initialized inside the "Try", which means that the "catch" would error, because the PSQL is not initialized, unless it's a global variable.

You should change to:
B4X:
Public Sub Accept_Cl(ACData As Map)
   'Init ouside the try/catch:
   Private PSQL As SQL = Main.Pool.GetConnection
   Private OSQL As SQL = Main.oPool.GetConnection
   Try
      AcceptCl(ACData,PSQL,OSQL) 'This Sub does all the SQL work.
   Catch
        Log("Error Ev_AcceptCl")
    End Try
    PSQL.Close
    OSQL.Close
End Sub

I'm wondering something else. I see a lot of Try...Catch.... Correct me if I'm wrong, but I think try/catch has to keep in memory both versions of the code in case the Try fails. If this is right, maybe all the try/catch are adding a lot to the memory (you even have nested try/catch)?
 
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
I see an error in your code, but maybe not related to your memory leak. In all your samples, the PSQL variable is initialized inside the "Try", which means that the "catch" would error, because the PSQL is not initialized, unless it's a global variable.

You should change to:
B4X:
Public Sub Accept_Cl(ACData As Map)
   'Init ouside the try/catch:
   Private PSQL As SQL = Main.Pool.GetConnection
   Private OSQL As SQL = Main.oPool.GetConnection
   Try
      AcceptCl(ACData,PSQL,OSQL) 'This Sub does all the SQL work.
   Catch
        Log("Error Ev_AcceptCl")
    End Try
    PSQL.Close
    OSQL.Close
End Sub

I'm wondering something else. I see a lot of Try...Catch.... Correct me if I'm wrong, but I think try/catch has to keep in memory both versions of the code in case the Try fails. If this is right, maybe all the try/catch are adding a lot to the memory (you even have nested try/catch)?
Hello jmon!
I have already changed to this coding style, as Erel suggested at post #21.
The app is running for 6,5 hours and I see a more healthy behavior, but I need to see that before evening again.
 
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
I've found at one thread parked (with the Eclipse MAT tool) the following:
B4X:
Object / Stack Frame                                                                                                        |Name              | Shallow Heap | Retained Heap |Context Class Loader                          |Is Daemon
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
java.lang.Thread @ 0x6c3811238                                                                                              |pool-1-thread-1153|          104 |         3.272 |sun.misc.Launcher$AppClassLoader @ 0x6c000c160|false
|- at sun.misc.Unsafe.park(ZJ)V (Native Method)                                                                             |                  |              |               |                                              |
|- at java.util.concurrent.locks.LockSupport.park(Ljava/lang/Object;)V (LockSupport.java:186)                               |                  |              |               |                                              |
|  '- <local> java.lang.Thread @ 0x6c3811238  pool-1-thread-1153 Thread                                                     |                  |          104 |         3.272 |                                              |
|     |- <class> class java.lang.Thread @ 0x6c02dede8 System Class                                                          |                  |           40 |           200 |                                              |
|     |- contextClassLoader sun.misc.Launcher$AppClassLoader @ 0x6c000c160                                                  |                  |           80 |     5.145.552 |                                              |
|     |- group java.lang.ThreadGroup @ 0x6c0078130  main                                                                    |                  |           48 |         8.304 |                                              |
|     |- <Java Local> java.util.concurrent.ThreadPoolExecutor @ 0x6c00787d8                                                 |                  |           72 |        47.584 |                                              |
|     |- inheritedAccessControlContext java.security.AccessControlContext @ 0x6c0078928                                     |                  |           32 |            56 |                                              |
|     |- <Java Local> java.lang.Thread @ 0x6c3811238  pool-1-thread-1153 Thread                                             |                  |          104 |         3.272 |                                              |
|     |- name char[18] @ 0x6c38112a0  pool-1-thread-1153                                                                    |                  |           56 |            56 |                                              |
|     |- <Java Local>, target java.util.concurrent.ThreadPoolExecutor$Worker @ 0x6c38112d8                                  |                  |           48 |            48 |                                              |
|     |- threadLocals java.lang.ThreadLocal$ThreadLocalMap @ 0x6c3814398                                                    |                  |           24 |         3.040 |                                              |
|     |- <Java Local>, parkBlocker java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject @ 0x6c3814e60      |                  |           24 |            24 |                                              |
|     |  |- <class> class java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject @ 0x6c0321eb8 System Class  |                  |           16 |            16 |                                              |
|     |  |- this$0 java.util.concurrent.locks.ReentrantLock$NonfairSync @ 0x6c3814e78                                       |                  |           32 |            64 |                                              |
|     |  |- lastWaiter, firstWaiter java.util.concurrent.locks.AbstractQueuedSynchronizer$Node @ 0x6c516eb98                |                  |           32 |            32 |                                              |
|     |  '- Total: 3 entries                                                                                                |                  |              |               |                                              |
|     |- blockerLock java.lang.Object @ 0x6c3814e98                                                                         |                  |           16 |            16 |                                              |
|     |- <Java Local> anywheresoftware.b4a.keywords.SimpleMessageLoop @ 0x6c383a860                                         |                  |           16 |            16 |                                              |
|     |- <Java Local> java.util.concurrent.LinkedBlockingQueue @ 0x6c383a870                                                |                  |           48 |           144 |                                              |
|     |- <Java Local> java.util.concurrent.atomic.AtomicInteger @ 0x6c383a8a0                                               |                  |           16 |            16 |                                              |
|     |- <Java Local> java.util.concurrent.locks.ReentrantLock @ 0x6c383a8b0                                                |                  |           16 |            16 |                                              |
|     |- <Java Local> anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler @ 0x6c4c17af8                       |                  |           16 |            16 |                                              |
|     |- <Java Local> anywheresoftware.b4a.StandardBA @ 0x6c4c17b08                                                         |                  |           32 |            32 |                                              |
|     |- <Java Local> my.wsserver.pushb4a @ 0x6c4c17b28                                                                     |                  |          112 |         4.368 |                                              |
|     |  |- <class> class my.wsserver.pushb4a @ 0x6c02bd8a0                                                                 |                  |            8 |             8 |                                              |
|     |  |- _vvvvvvvvvv3, _vvvvvvvvvv2 java.lang.String @ 0x6c003df50                                                       |                  |           24 |            40 |                                              |
|     |  |- ba anywheresoftware.b4a.StandardBA @ 0x6c4c17b08                                                                |                  |           32 |            32 |                                              |
|     |  |- _vvvvvvvvv2 anywheresoftware.b4j.object.WebSocket @ 0x6c4c17b98                                                 |                  |           32 |            64 |                                              |
|     |  |- _vvvvvvvvv3 java.lang.String @ 0x6c4c17bd8  253\u0391                                                           |                  |           24 |            48 |                                              |
|     |  |- _vvvvvvvvvv1 java.lang.String @ 0x6c4c17c08  RO,NA                                                              |                  |           24 |            56 |                                              |
|     |  |- _v5 b4j.example.jstringfunctions @ 0x6c4c17c40                                                                  |                  |           24 |            56 |                                              |
|     |  |  |- <class> class b4j.example.jstringfunctions @ 0x6c0204b70                                                     |                  |            8 |             8 |                                              |
|     |  |  |  |- <class> class java.lang.Class @ 0x6c0053df0 System Class                                                  |                  |           40 |            56 |                                              |
|     |  |  |  |- <classloader> sun.misc.Launcher$AppClassLoader @ 0x6c000c160                                              |                  |           80 |     5.145.552 |                                              |
|     |  |  |  |- htSubs java.util.HashMap @ 0x6c0204980                                                                    |                  |           48 |        15.704 |                                              |
|     |  |  |  |- <super> class anywheresoftware.b4a.B4AClass$ImplB4AClass @ 0x6c02bdb20                                    |                  |            0 |             0 |                                              |
|     |  |  |  '- Total: 4 entries                                                                                          |                  |              |               |                                              |
|     |  |  |- ba anywheresoftware.b4a.StandardBA @ 0x6c4c17c58                                                             |                  |           32 |            32 |                                              |
|     |  |  |  |- <class> class anywheresoftware.b4a.StandardBA @ 0x6c0321a88                                               |                  |            8 |        61.160 |                                              |
|     |  |  |  |- htSubs java.util.HashMap @ 0x6c0204980                                                                    |                  |           48 |        15.704 |                                              |
|     |  |  |  |- className java.lang.String @ 0x6c0204bd0  b4j.example.jstringfunctions                                    |                  |           24 |            96 |                                              |
|     |  |  |  |- ownerThread java.lang.Thread @ 0x6c3811238  pool-1-thread-1153 Thread                                     |                  |          104 |         3.272 |                                              |
|     |  |  |  |- eventsTarget b4j.example.jstringfunctions @ 0x6c4c17c40                                                   |                  |           24 |            56 |                                              |
|     |  |  |  '- Total: 5 entries                                                                                          |                  |              |               |                                              |
|     |  |  '- Total: 2 entries                                                                                             |                  |              |               |                                              |
|     |  |- _vvvvvvvvvv5 anywheresoftware.b4a.objects.collections.Map @ 0x6c4c17c78                                         |                  |           16 |         3.752 |                                              |
|     |  |  |- <class> class anywheresoftware.b4a.objects.collections.Map @ 0x6c02c2ce0                                     |                  |            0 |             0 |                                              |
|     |  |  |  |- <class> class java.lang.Class @ 0x6c0053df0 System Class                                                  |                  |           40 |            56 |                                              |
|     |  |  |  |- <classloader> sun.misc.Launcher$AppClassLoader @ 0x6c000c160                                              |                  |           80 |     5.145.552 |                                              |
|     |  |  |  |- <super> class anywheresoftware.b4a.AbsObjectWrapper @ 0x6c0322460                                         |                  |            8 |           192 |                                              |
|     |  |  |  '- Total: 3 entries                                                                                          |                  |              |               |                                              |
|     |  |  |- object anywheresoftware.b4a.objects.collections.Map$MyMap @ 0x6c4c17c88                                      |                  |           32 |         3.736 |                                              |
|     |  |  |  |- <class> class anywheresoftware.b4a.objects.collections.Map$MyMap @ 0x6c02dd130                            |                  |            0 |             0 |                                              |
|     |  |  |  |- innerMap java.util.LinkedHashMap @ 0x6c4c17ca8                                                            |                  |           56 |         3.704 |                                              |
|     |  |  |  '- Total: 2 entries                                                                                          |                  |              |               |                                              |
|     |  |  '- Total: 2 entries                                                                                             |                  |              |               |                                              |
|     |  |- _vvvvvvvvvv6 java.lang.String @ 0x6c4c18288  753                                                                |                  |           24 |            48 |                                              |
|     |  |- _vvvvvvvvv4 java.lang.String @ 0x6c5189d50  23.678047108900248                                                  |                  |           24 |            80 |                                              |
|     |  |- _vvvvvvvvv5 java.lang.String @ 0x6c5189da0  37.9781341936764                                                    |                  |           24 |            72 |                                              |
|     |  |- _vvvvvvvvv6 java.lang.String @ 0x6c5189de8  4                                                                   |                  |           24 |            48 |                                              |
|     |  |- _vvvvvvvvv7 java.lang.String @ 0x6c5189e18  58                                                                  |                  |           24 |            48 |                                              |
|     |  |- _vvvvvvvvv0 java.lang.String @ 0x6c5189e48  1                                                                   |                  |           24 |            48 |                                              |
|     |  '- Total: 14 entries                                                                                               |                  |              |               |                                              |
|     |- <Java Local> java.util.concurrent.Executors$RunnableAdapter @ 0x6c4cadc70                                          |                  |           24 |            24 |                                              |
|     |  |- <class> class java.util.concurrent.Executors$RunnableAdapter @ 0x6c04b0008 System Class                         |                  |            0 |             0 |                                              |
|     |  |- task anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler @ 0x6c4c17af8                            |                  |           16 |            16 |                                              |
|     |  '- Total: 2 entries                                                                                                |                  |              |               |                                              |
|     |- <Java Local> java.util.concurrent.FutureTask @ 0x6c4cadc88                                                         |                  |           32 |            32 |                                              |
|     |  |- <class> class java.util.concurrent.FutureTask @ 0x6c04b26d0 System Class                                        |                  |           56 |            56 |                                              |
|     |  |  |- <class> class java.lang.Class @ 0x6c0053df0 System Class                                                     |                  |           40 |            56 |                                              |
|     |  |  |- <classloader> java.lang.ClassLoader @ 0x0  <system class loader>                                             |                  |           64 |            64 |                                              |
|     |  |  |- <super> class java.lang.Object @ 0x6c0053b38 System Class                                                    |                  |            0 |             0 |                                              |
|     |  |  |- UNSAFE sun.misc.Unsafe @ 0x6c0078720                                                                         |                  |           16 |            16 |                                              |
|     |  |  '- Total: 4 entries                                                                                             |                  |              |               |                                              |
|     |  |- runner java.lang.Thread @ 0x6c3811238  pool-1-thread-1153 Thread                                                |                  |          104 |         3.272 |                                              |
|     |  |  |- <class> class java.lang.Thread @ 0x6c02dede8 System Class                                                    |                  |           40 |           200 |                                              |
|     |  |  |- contextClassLoader sun.misc.Launcher$AppClassLoader @ 0x6c000c160                                            |                  |           80 |     5.145.552 |                                              |
|     |  |  |- group java.lang.ThreadGroup @ 0x6c0078130  main                                                              |                  |           48 |         8.304 |                                              |
|     |  |  |- <Java Local> java.util.concurrent.ThreadPoolExecutor @ 0x6c00787d8                                           |                  |           72 |        47.584 |                                              |
|     |  |  |- inheritedAccessControlContext java.security.AccessControlContext @ 0x6c0078928                               |                  |           32 |            56 |                                              |
|     |  |  |- <Java Local> java.lang.Thread @ 0x6c3811238  pool-1-thread-1153 Thread                                       |                  |          104 |         3.272 |                                              |
|     |  |  |- name char[18] @ 0x6c38112a0  pool-1-thread-1153                                                              |                  |           56 |            56 |                                              |
|     |  |  |- <Java Local>, target java.util.concurrent.ThreadPoolExecutor$Worker @ 0x6c38112d8                            |                  |           48 |            48 |                                              |
|     |  |  |- threadLocals java.lang.ThreadLocal$ThreadLocalMap @ 0x6c3814398                                              |                  |           24 |         3.040 |                                              |
|     |  |  |- <Java Local>, parkBlocker java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject @ 0x6c3814e60|                  |           24 |            24 |                                              |
|     |  |  |- blockerLock java.lang.Object @ 0x6c3814e98                                                                   |                  |           16 |            16 |                                              |
|     |  |  |- <Java Local> anywheresoftware.b4a.keywords.SimpleMessageLoop @ 0x6c383a860                                   |                  |           16 |            16 |                                              |
|     |  |  |- <Java Local> java.util.concurrent.LinkedBlockingQueue @ 0x6c383a870                                          |                  |           48 |           144 |                                              |
|     |  |  |- <Java Local> java.util.concurrent.atomic.AtomicInteger @ 0x6c383a8a0                                         |                  |           16 |            16 |                                              |
|     |  |  |- <Java Local> java.util.concurrent.locks.ReentrantLock @ 0x6c383a8b0                                          |                  |           16 |            16 |                                              |
|     |  |  |- <Java Local> anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler @ 0x6c4c17af8                 |                  |           16 |            16 |                                              |
|     |  |  |- <Java Local> anywheresoftware.b4a.StandardBA @ 0x6c4c17b08                                                   |                  |           32 |            32 |                                              |
|     |  |  |- <Java Local> my.wsserver.pushb4a @ 0x6c4c17b28                                                               |                  |          112 |         4.368 |                                              |
|     |  |  |- <Java Local> java.util.concurrent.Executors$RunnableAdapter @ 0x6c4cadc70                                    |                  |           24 |            24 |                                              |
|     |  |  |- <Java Local> java.util.concurrent.FutureTask @ 0x6c4cadc88                                                   |                  |           32 |            32 |                                              |
|     |  |  |- <Java Local> java.util.concurrent.locks.AbstractQueuedSynchronizer$Node @ 0x6c516eb98                        |                  |           32 |            32 |                                              |
|     |  |  '- Total: 21 entries                                                                                            |                  |              |               |                                              |
|     |  |- callable java.util.concurrent.Executors$RunnableAdapter @ 0x6c4cadc70                                           |                  |           24 |            24 |                                              |
|     |  |  |- <class> class java.util.concurrent.Executors$RunnableAdapter @ 0x6c04b0008 System Class                      |                  |            0 |             0 |                                              |
|     |  |  |- task anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler @ 0x6c4c17af8                         |                  |           16 |            16 |                                              |
|     |  |  '- Total: 2 entries                                                                                             |                  |              |               |                                              |
|     |  '- Total: 3 entries                                                                                                |                  |              |               |                                              |
|     |- <Java Local> java.util.concurrent.locks.AbstractQueuedSynchronizer$Node @ 0x6c516eb98                              |                  |           32 |            32 |                                              |
|     |  |- <class> class java.util.concurrent.locks.AbstractQueuedSynchronizer$Node @ 0x6c0300ab8 System Class             |                  |           24 |            56 |                                              |
|     |  |  |- <class> class java.lang.Class @ 0x6c0053df0 System Class                                                     |                  |           40 |            56 |                                              |
|     |  |  |- <classloader> java.lang.ClassLoader @ 0x0  <system class loader>                                             |                  |           64 |            64 |                                              |
|     |  |  |- <super> class java.lang.Object @ 0x6c0053b38 System Class                                                    |                  |            0 |             0 |                                              |
|     |  |  |- SHARED java.util.concurrent.locks.AbstractQueuedSynchronizer$Node @ 0x6c0300b28                              |                  |           32 |            32 |                                              |
|     |  |  '- Total: 4 entries                                                                                             |                  |              |               |                                              |
|     |  |- thread java.lang.Thread @ 0x6c3811238  pool-1-thread-1153 Thread                                                |                  |          104 |         3.272 |                                              |
|     |  '- Total: 2 entries                                                                                                |                  |              |               |                                              |
|     '- Total: 21 entries                                                                                                  |                  |              |               |                                              |
|- at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await()V (AbstractQueuedSynchronizer.java:2043) |                  |              |               |                                              |
|- at java.util.concurrent.LinkedBlockingQueue.take()Ljava/lang/Object; (LinkedBlockingQueue.java:442)                      |                  |              |               |                                              |
|  |- <local> java.util.concurrent.LinkedBlockingQueue @ 0x6c383a870                                                        |                  |           48 |           144 |                                              |
|  |- <local> java.util.concurrent.atomic.AtomicInteger @ 0x6c383a8a0                                                       |                  |           16 |            16 |                                              |
|  |- <local> java.util.concurrent.locks.ReentrantLock @ 0x6c383a8b0                                                        |                  |           16 |            16 |                                              |
|  |  |- <class> class java.util.concurrent.locks.ReentrantLock @ 0x6c03006c0 System Class                                  |                  |            8 |             8 |                                              |
|  |  |  |- <class> class java.lang.Class @ 0x6c0053df0 System Class                                                        |                  |           40 |            56 |                                              |
|  |  |  |  |- <class> class java.lang.Class @ 0x6c0053df0 System Class                                                     |                  |           40 |            56 |                                              |
|  |  |  |  |- <classloader> java.lang.ClassLoader @ 0x0  <system class loader>                                             |                  |           64 |            64 |                                              |
|  |  |  |  |- <super> class java.lang.Object @ 0x6c0053b38 System Class                                                    |                  |            0 |             0 |                                              |
|  |  |  |  |- reflectionFactory sun.reflect.ReflectionFactory @ 0x6c0053e70                                                |                  |           16 |            16 |                                              |
|  |  |  |  |- serialPersistentFields java.io.ObjectStreamField[0] @ 0x6c0053e80                                            |                  |           16 |            16 |                                              |
|  |  |  |  |- allPermDomain java.security.ProtectionDomain @ 0x6c0563770                                                   |                  |           40 |           288 |                                              |
|  |  |  |  '- Total: 6 entries                                                                                             |                  |              |               |                                              |
|  |  |  |- <classloader> java.lang.ClassLoader @ 0x0  <system class loader>                                                |                  |           64 |            64 |                                              |
|  |  |  |- <super> class java.lang.Object @ 0x6c0053b38 System Class                                                       |                  |            0 |             0 |                                              |
|  |  |  |  |- <class> class java.lang.Class @ 0x6c0053df0 System Class                                                     |                  |           40 |            56 |                                              |
|  |  |  |  |- <classloader> java.lang.ClassLoader @ 0x0  <system class loader>                                             |                  |           64 |            64 |                                              |
|  |  |  |  |  '- <class> class java.lang.ClassLoader @ 0x6c02dfc18 System Class                                            |                  |           32 |           680 |                                              |
|  |  |  |  '- Total: 2 entries                                                                                             |                  |              |               |                                              |
|  |  |  '- Total: 3 entries                                                                                                |                  |              |               |                                              |
|  |  |- sync java.util.concurrent.locks.ReentrantLock$NonfairSync @ 0x6c3814e78                                            |                  |           32 |            64 |                                              |
|  |  '- Total: 2 entries                                                                                                   |                  |              |               |                                              |
|  '- Total: 3 entries                                                                                                      |                  |              |               |                                              |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Do I misuse the jstringfunctions or the strings library?
When I use them, do they need invalidation?
Note that more or less, almost all parked threads I opened, gave me the same results.
 
Last edited:
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
I'm going on searching for the real problem my server has.
I've found the following at top consumers:
B4X:
Top Consumers

(Only this instance is referred as biggest object!)
org.eclipse.jetty.websocket.server.WebSocketServerFactory @ 0x6c02e0780 »11226.565.480

Retained Set

Possible Memory Waste


Duplicate Strings



Found 129 occurrences of char[] with at least 10 instances having identical content. Total size is 2.925.712 bytes.

Top elements include:
•2.552 × http://XXX.XXX.XX.XXX:65535/wsserver/listen\u0000\... (272 bytes)
•5.104 × XXX.XXX.XX.XXX:65535 (56 bytes)
•2.552 × ws://XXX.XXX.XX.XXX:65535/wsserver/listen (104 bytes)
•2.552 × //XXX.XXX.XX.XXX:65535/wsserver/listen (96 bytes)
•5.104 × /wsserver/listen (48 bytes)

Details »

Empty Collections



Detected the following empty collections:
•17.866 instances of java.util.concurrent.CopyOnWriteArrayList retain >= 1.572.208 bytes.

Details »

Collection Fill Ratios



Detected the following collections with fill ratios below 20%:
•20.417 instances of java.util.ArrayList retain >= 2.470.432 bytes.
What do all they mean?
Why I have so many references to the server_ip?
Which could be this one instance that consumes so many resources?
 
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
It is more or less impossible to say anything from this information. Only you are familiar with your code.

Does it crash? Can you post the error message?
Hello Erel! (Thank you as usual!)
Yes, it crashes after 8-10 days uptime.
The error message I haven't been able to catch it, because when I'm being informed for crash, the message has been lost from the terminal window.
Are you adding class instances to a global map? Are you removing them eventually?
Yes, I do. I recently changed the map to threadsafe.
 
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
One notice:
Why the following seem to consume the biggest memory space?
B4X:
Class Name             | Objects | Shallow Heap | Retained Heap
----------------------------------------------------------------
java.lang.Object[]     | 223.501 |   25.734.416 |            
char[]                 | 390.713 |   20.742.760 |            
java.lang.String       | 377.088 |    9.050.112 |            
java.util.HashMap$Entry| 190.610 |    6.099.520 |            
----------------------------------------------------------------
Is it possible to avoid all that, if I use Java 8?
I'm currently using Java 1.7.0_80 but it's quite difficult to upgrade Java, because this production server has to be up 24/7.
 
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
You could send me your code if you like, maybe I could have a look ?
Hello jmon!
Thank you very much for your kind suggestion!
This post has the file RMTunnel.zip, which is my whole project.
I have sent you the password to the personal conversation...
 
Last edited:
Upvote 0

dar2o3

Active Member
Licensed User
Longtime User
Please publish here the solution when they find it, maybe someone will solve something.
 
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
The only thing I've found reading my code, was a transaction without begin-successful. I don't know if this is the reason of remaining open connections...
Hi! After a few days watching my system, the conclusion is that the quoted statement is true. The remaining open connections caused by the begin-successful I had forgotten!
 
Upvote 0
Top