Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory consumption when using DriverManager.getConnection with UCanAccess

I am using JDBC along with UCanAccess in order to create a connection to a MS Access file via direct filepath to store a specific table into a JSON object. However, my line of code

conn = DriverManager.getConnection(s1+inFilePath, user, pass);

where conn is an uninitialized Connection object, that creates the connection is causing some sort of memory leak that eventually causes the GC overhead limit to be exceeded.

Is there any way to get around this problem? I have tried changing the heap size with no results.

like image 324
matt Avatar asked Apr 01 '16 20:04

matt


1 Answers

It is not a memory leak. UCanAccess is consuming memory as part of its normal operation.

UCanAccess uses an HSQLDB "mirror" of the Access database to support SQL operations, and by default that mirror database is created in memory. Therefore if you connect to an Access database that has tables containing 30 MB of data then UCanAccess will use ~30 MB of memory to store the mirror database.

Appending ;memory=false to the connection URL will tell UCanAccess to create the HSQLDB mirror database on disk instead of in memory. That will will reduce the memory requirements significantly but it will also take longer to establish the connection (i.e., create the mirror database).

UCanAccess also "mirrors" all of the tables that it finds in the specified database. So, if you are only interested in working with one particular table in a database named "main.accdb" then you can

  • create a new Access database, e.g., "link.accdb"
  • create a Linked Table in "link.accdb" that points to the actual table in "main.accdb", and then
  • use UCanAccess to open "link.accdb".

Using the above procedure, UCanAccess only mirrors the one table.

There are several other options to control the mirroring behaviour of UCanAccess; see the UCanAccess website for details.

like image 142
Gord Thompson Avatar answered Oct 18 '22 23:10

Gord Thompson