B4J Question MySQL prepared statements and memory leaks

vfafou

Well-Known Member
Licensed User
Longtime User
Hello!
I have the very often INFO from C3P0 pool connection:
B4X:
Sep 11, 2016 12:44:44 PM com.mchange.v2.c3p0.stmt.GooGooStatementCache assimilateNewCheckedOutStatement
INFO: Multiply prepared statement! Select A.Z_ZONE As ZONE, A.Z_CD_STATION As CD_STATION, A.Z_U_DTTM, count(*) As SEQ From zones A Join zones B ON A.Z_ZONE = B.Z_ZONE And A.Z_U_DTTM >= B.Z_U_DTTM Where A.Z_CD_STATION = ? Group By A.Z_ZONE, A.Z_CD_STATION Order By 1,3
I'm closing all connections and statements properly!
Memory analyzer of Eclipse, gives me relative to this INFO, memory leaks suspect!

What could I do to overcome this?

Thank you in advance!
 

vfafou

Well-Known Member
Licensed User
Longtime User
Hello Erel! Thank you for your response...
Yes, I'm closing all the ResultSets!
The code executed after this statement is:
B4X:
Try
        rs = ASQL.ExecQuery2(SQLQuery,Array As String(aZone,aSeqDtTm))
        Do While rs.NextRow
           ZMesg = "Z;" & rs.GetInt("ZONE") & ";" & rs.GetInt("SEQ") & ";NA;NA"
           CallSubDelayed3(PushShared, "SendWebClientMessage",ZMesg,rs.GetString("CD_STATION"))
        Loop
        rs.Close
    Catch
        If rs.IsInitialized Then rs.Close
        Log("Error AnnZone: " & LastException)
    End Try

Is there any unpredictable behavior of the Try-Catch block?
 
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
Hi Erel,

I'm getting the ASQL as below:
B4X:
Public oPool As ConnectionPool  '(Created in the main module)
oPool.Initialize(DriverClass, JdbcUrl, DBUser, DBPassword)
I'm calling the sub with ASQL from another sub:
B4X:
Public Sub GetZoneAnnounce
     Dim OSQL As SQL = oPool.GetConnection

     AnnounceZone(OSQL,SomeVar)  'This Sub has the ASQL object

     OSQL.Close
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Looks good.

I usually add a Try / Catch block:
B4X:
Dim OSQL As SQL = opool.GetConnection
Try
 ...
Catch
 Log("Error: " & LastException)
End Try
OSQL.Close

I've checked the ResultSet implementation. It closes the prepared statement when it is closed. It is most probably a bug in your code. Monitor the process with a profiler and see whether there is a real leak. Maybe the statements are closed but not immediately.
 
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
Hello Erel,
After a full Garbage Collection performed, I ran profiler for a few minutes and I saw that the displayed objects are growing very fast! The two images are taken within 10 seconds!

Desktop.png




Desktop1.png


What do all they mean?
Is it actually a memory leak?
I have been watching last 3 days and after a full GC (once a day) I have seen that every day the heap size increases by ~35MB.
Is it reasonable?
Do you see any leak suspected object at the images?

Thank you in advance!
 
Upvote 0
Top