I was running into a memory leak using mathworks' database toolbox with mysql. If I was returning large amounts of data, eventually the I would get an out of memory error running out of java heap space.
I had seen this before and used the com.mysql.jdbc.JDBC4Prepared Statement and com.mysql.jdbc.JDBC4ResultSet driver calls myself. When you do this, you have to be sure to call the close() methods of each of those, or else you have the same problem.
I remembered this today when mathworks shoddy object was hitting heap problems by just exec'ing the same query and fetching the results a few thousand times. It turns out you can see the mysql jdbc objects in the mathworks cursor and resultset objects:
curs = exec(dbConn, sqlStr)
rs = fetch(curs)
curs =
Attributes: []
Data: 0
DatabaseObject: [1x1 database]
RowLimit: 0
SQLQuery: 'xxxxxomitxxxx'
Message: []
Type: 'Database Cursor Object'
ResultSet: [1x1 com.mysql.jdbc.JDBC4ResultSet]
Cursor: [1x1 com.mathworks.toolbox.database.sqlExec]
Statement: [1x1 com.mysql.jdbc.StatementImpl]
Fetch: 0
rs =
Attributes: []
Data: {2497x8 cell}
DatabaseObject: [1x1 database]
RowLimit: 0
SQLQuery: 'xxxxxomitxxxx'
Message: []
Type: 'Database Cursor Object'
ResultSet: [1x1 com.mysql.jdbc.JDBC4ResultSet]
Cursor: [1x1 com.mathworks.toolbox.database.sqlExec]
Statement: [1x1 com.mysql.jdbc.StatementImpl]
Fetch: [1x1 com.mathworks.toolbox.database.fetchTheData]