Live Threads: ~1120
Used Heap: ~850MB before GC, ~140MB after GC
Total Started Threads: ~1700
Live Threads: ~980
Used Heap: ~1.1GB before GC, ~210MB after GC
Total Started Threads: ~2300
Live Threads: ~510
Used Heap: ~1.3GB before GC, ~250MB after GC
Total Started Threads: ~2900
Live Threads: ~510
Used Heap: ~230MB
Total Started Threads: ~2900
Live Threads: ~226
Used Heap: ~880MB before GC, ~47MB after GC
Total Started Threads: ~247
java -Xms2G -Xmx5G -XX:MaxPermSize=256m -XX:NewRatio=1 -XX:+UseConcMarkSweepGC -verbosegc -jar MyServer.jar
Dim PSQL As SQL = Main.Pool.GetConnection
Try
...
Catch
Log("error: "& LastException)
End Try
PSQL.Close
Hi jmon!Do you use Cursors with SQL? If yes, make sure they are all closed before calling SQL.close.
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
Hello jmon!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)?
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 | | | | |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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.
Hello Erel! (Thank you as usual!)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?
Yes, I do. I recently changed the map to threadsafe.Are you adding class instances to a global map? Are you removing them eventually?
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 |
----------------------------------------------------------------
You could redirect the stderr and stdOut to a filethe message has been lost from the terminal window.
We cannot know without analyzing your project.Why the following seem to consume the biggest memory space?
Thank you very much, Erel!We cannot know without analyzing your project.
You could send me your code if you like, maybe I could have a look ?What could I do for this?
Hello jmon!You could send me your code if you like, maybe I could have a look ?
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!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...
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?