5

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.

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
matt
  • 53
  • 3
  • 1
    Have you tried including `;memory=false` in the connection URL to see if that helps? – Gord Thompson Apr 01 '16 at 20:48
  • I tried adding that and the .getConnection() line does not finish executing – matt Apr 01 '16 at 21:16
  • I'm not sure what you are asking. Explain what you think would be causing the memory leak. Show more code for context. Do you actually close the connection when you are done with it? – Mark Rotteveel Apr 02 '16 at 07:45
  • I found a way around my problem by using Jackcess to pull from the file instead of UCanAccess. Thank you – matt Apr 02 '16 at 13:54

1 Answers1

4

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.

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418