B4J Question JAVAW And Memory Management

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hello All

I have a server app, (Non UI as per Erel suggestion), It originally had a UI on it, now removed this morning. I have 2 B4A clients connecting to it and sending a PING every 5 seconds.

I noticed that the JAVAW.EXE process memory keep creeping up and it did appear that no garbage collection was being performed.

It started off a 22 Mb and within a short period of time it was up to 90 mbs (not cool !)

So, I remembered in the old days of coding in Clipper at the end of each function if you did not use the release <var name> command memory was consumed.

So. At the end of each function I set all vars except int' and bool's = NULL. This appears to have stabilized the memory growth, a lot.

Also if you use Visual VM to monitor your app it will have an affect of the memory using of the app being monitored. This maybe not be true but it was noticed.

Comments are welcome on this please.

Regards

John.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
There is no reason to set the variables to null. The reference will be removed when the sub ends in both ways.

90mb for a desktop process is not too much. Assuming that it didn't continue to grow at some point then you don't have any memory leaks.

As I wrote in another thread, the "online examples" hosted on this server which use timers and a bunch of other stuff were running for 4 months and the memory usage was constant.

If you like you can limit the memory allocated for the JVM. In most cases it is not needed.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi Erel

Just did another test. The 2 B4A clients were offline. Sent 50 messages for each client. The Server stores them in an SQL db because the clients were offline. The client connect and get all there messages.

Prior to connecting the javaw was at 21mb, after the messages are delivered it's a 40 mb, even though I had cleared all the associated vars and obj's (resultsets etc). Am I wrong in assuming that the size would reduce back to mid 20's anyway, or am I missing something ? I have definitely improved the mem allocation by Nulling the vars etc.

Regards

John.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It will not be reduced to 20mb as the default maximum memory size set for each JVM process is higher. If you like you can set it yourself to 16mb and then the allocated memory will be lower (assuming that no more than 16mb is required at each point).

As a general rule, if you are not experiencing any out of memory issues then you do not need to worry about it.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi Erel

Did some testing last night, sent 1000 messages to the 2 clients...this is what happened:


Summery of what is going on:

Messages arrive in from back office systerm


end of log file:

02/23/2015 19:26:48.086 - store_for_delivery() (MyMap) {server_id=PP, message_id=7DF217131A1800000014AE56F3PLPT, message_text=Map V-W1,Lone Worker #1, \\IS-DEV-CORE\Isle Systems Data\HTMLDOCS\0001-2015022315311991-001420-w11.html, message_date=2015/02/23 19:26:24, message_from=1912, message_from_name=Responder #1, message_to=WGSV, message_to_name=Responder #1, message_type=01, message_type_text=Normal, message_status=0, message_response=0, message_style=6, message_mobile_address=0879681912, mes...
02/23/2015 19:26:48.664 - process_inbound_queue() - 7DF217131A1800000014AE56F3PLPT, 29
02/23/2015 19:26:48.670 - process_client_queue(true) sending 100PP0001-2015022315311991PLPT7DF217131A1800000014AE56F3PLPTPLPTPPS1true119120001Lone Worker #12292015/02/23 19:26:24Map V-W1,Lone Worker #1, \\IS-DEV-CORE\Isle Systems Data\HTMLDOCS\0001-2015022315311991-001420-w11.html
02/23/2015 19:26:48.877 - process_packet() p.len = 38, p = 97DF217123A2B00000014AE38F8PLPTtrue
02/23/2015 19:26:48.881 - update_message_status( 7DF217123A2B00000014AE38F8PLPT, true )
02/23/2015 19:26:48.886 - UPDATE client_inbox SET message_status = 1 WHERE message_id = '7DF217123A2B00000014AE38F8PLPT'
02/23/2015 19:26:50.317 - store_for_delivery() (MyMap) {server_id=PP, message_id=7DF217131A1A00000014AE56F4PLPT, message_text=Lone Worker #1, http://maps.google.com/maps?q=53.084447,-6.107112&z=15 , message_date=2015/02/23 19:26:26, message_from=1912, message_from_name=Responder #1, message_to=WGSV, message_to_name=Responder #1, message_type=01, message_type_text=Normal, message_status=0, message_response=0, message_style=6, message_mobile_address=0879681912, message_source_pid=PLPT, message_sou...
02/23/2015 19:26:50.465 - process_inbound_queue() - 7DF217131A1A00000014AE56F4PLPT, 43
02/23/2015 19:26:51.062 - process_client_queue(false) sending 100PP0001-2015022315311991PLPT7DF217131A1A00000014AE56F4PLPTPLPTPPS1true119120001Lone Worker #12432015/02/23 19:26:26Lone Worker #1, http://maps.google.com/maps?q=53.084447,-6.107112&z=15
02/23/2015 19:26:51.226 - store_for_delivery() (MyMap) {server_id=PP, message_id=7DF217131A1B00000014AE56F7PLPT, message_text=Map V-W1,Lone Worker #1, \\IS-DEV-CORE\Isle Systems Data\HTMLDOCS\0001-2015022315311991-001420-w11.html, message_date=2015/02/23 19:26:27, message_from=5356, message_from_name=Responder #2, message_to=WGSV, message_to_name=Responder #2, message_type=01, message_type_text=Normal, message_status=0, message_response=0, message_style=6, message_mobile_address=0872305356, mes...
02/23/2015 19:26:51.234 - store_for_delivery() (MyMap) {server_id=PP, message_id=7DF217131A1B00000014AE56F8PLPT, message_text=Lone Worker #1, http://maps.google.com/maps?q=53.084447,-6.107112&z=15 , message_date=2015/02/23 19:26:27, message_from=5356, message_from_name=Responder #2, message_to=WGSV, message_to_name=Responder #2, message_type=01, message_type_text=Normal, message_status=0, message_response=0, message_style=6, message_mobile_address=0872305356, message_source_pid=PLPT, message_sou...
02/23/2015 19:26:52.431 - process_inbound_queue() - 7DF217131A1B00000014AE56F7PLPT, 29
02/23/2015 19:26:52.443 - process_client_queue(true) sending 100PP0001-2015022315311991PLPT7DF217131A1B00000014AE56F7PLPTPLPTPPS1true153560001Lone Worker #12292015/02/23 19:26:27Map V-W1,Lone Worker #1, \\IS-DEV-CORE\Isle Systems Data\HTMLDOCS\0001-2015022315311991-001420-w11.html
02/23/2015 19:26:53.970 - process_inbound_queue() - 7DF217131A1B00000014AE56F8PLPT, 43
02/23/2015 19:26:57.630 - process_client_queue(false) sending 100PP0001-2015022315311991PLPT7DF217131A1B00000014AE56F8PLPTPLPTPPS1true153560001Lone Worker #12432015/02/23 19:26:27Lone Worker #1, http://maps.google.com/maps?q=53.084447,-6.107112&z=15
02/23/2015 19:27:01.836 - process_packet() p.len = 38, p = 97DF217123A3000000014AE390FPLPTtrue
02/23/2015 19:27:04.136 - update_message_status( 7DF217123A3000000014AE390FPLPT, true )
02/23/2015 19:27:04.707 - UPDATE client_inbox SET message_status = 1 WHERE message_id = '7DF217123A3000000014AE390FPLPT'
02/23/2015 19:27:05.851 - process_packet() p.len = 38, p = 97DF21712381B00000014AE3653PLPTtrue
02/23/2015 19:27:06.425 - update_message_status( 7DF21712381B00000014AE3653PLPT, true )
02/23/2015 19:27:07.578 - UPDATE client_inbox SET message_status = 1 WHERE message_id = '7DF21712381B00000014AE3653PLPT'
02/23/2015 19:27:08.149 - store_for_delivery() (MyMap) {server_id=PP, message_id=7DF217131A1E00000014AE570BPLPT, message_text=Map V-W1,Lone Worker #1, \\IS-DEV-CORE\Isle Systems Data\HTMLDOCS\0001-2015022315311991-001421-w11.html, message_date=2015/02/23 19:26:30, message_from=1912, message_from_name=Responder #1, message_to=WGSV, message_to_name=Responder #1, message_type=01, message_type_text=Normal, message_status=0, message_response=0, message_style=6, message_mobile_address=0879681912, mes...
02/23/2015 19:27:10.958 - store_for_delivery() (MyMap) {server_id=PP, message_id=7DF217131A2100000014AE570CPLPT, message_text=Lone Worker #1, http://maps.google.com/maps?q=53.084447,-6.107112&z=15 , message_date=2015/02/23 19:26:33, message_from=1912, message_from_name=Responder #1, message_to=WGSV, message_to_name=Responder #1, message_type=01, message_type_text=Normal, message_status=0, message_response=0, message_style=6, message_mobile_address=0879681912, message_source_pid=PLPT, message_sou...
02/23/2015 19:27:12.701 - store_for_delivery() (MyMap) {server_id=PP, message_id=7DF217131A2100000014AE570FPLPT, message_text=Map V-W1,Lone Worker #1, \\IS-DEV-CORE\Isle Systems Data\HTMLDOCS\0001-2015022315311991-001421-w11.html, message_date=2015/02/23 19:26:33, message_from=5356, message_from_name=Responder #2, message_to=WGSV, message_to_name=Responder #2, message_type=01, message_type_text=Normal, message_status=0, message_response=0, message_style=6, message_mobile_address=0872305356, mes...
02/23/2015 19:27:14.409 - store_for_delivery() (MyMap) {server_id=PP, message_id=7DF217131A2100000014AE5710PLPT, message_text=Lone Worker #1, http://maps.google.com/maps?q=53.084447,-6.107112&z=15 , message_date=2015/02/23 19:26:33, message_from=5356, message_from_name=Responder #2, message_to=WGSV, message_to_name=Responder #2, message_type=01, message_type_text=Normal, message_status=0, message_response=0, message_style=6, message_mobile_address=0872305356, message_source_pid=PLPT, message_sou...
main._appstart (java line: 76)
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Thread-8"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Thread-1"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Thread-32490"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Thread-32488"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Thread-2"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "RMI TCP Connection(idle)"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Thread-94"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Thread-3"


Snapshot of VM1.3.8
upload_2015-2-24_9-14-57.png


I don't know if I cam causing the leak or why this is happening. I know you are busy with other stuff but some insights would be appreciated.

Regards

John.
 
Upvote 0
Top