> Is there any standard or H2 specific way to manage the size of an in-
> memory database? My application has a defined memory limit and I need
> to keep the DB size within this limit.
No, there is no such feature at the moment. Could you explain the use
case please? Why do you need it, what exactly is the problem? I don't
understand fully when this feature would be useful. I will then add a
feature request, and depending how useful it is and how popular it is,
it will be implemented sooner or later. But first some more
information about the use case, advantages over alternatives and so on
is required. Maybe there is a workaround, or somebody could propose an
alternative solution.
Regards,
Thomas
Sorry for the delay.
> When the max is reached a callback is made to an
> interface implemented by the application which can remove rows. Or
> perhaps when max memory is reached all inserts would fail with a low
> memory exception?
You could use the function MEMORY_FREE(), see
http://www.h2database.com/html/functions.html#memoryfree
> My goal is to store as much information as possible without causing an
> OutOfMemory exception.
I'm not sure if this a use case I like to support. There are many
problems, one is that Java does not support a lot of memory management
functions. Garbage collection details is not something you should rely
on. Calculating the used memory in H2 is not that easy: there is an
object cache, and if a value (VARCHAR, INT, DECIMAL,...) is already in
that cache no more memory is allocated except the pointer. I could
expose more cache management details (current number of cached rows,
estimated current cache size) but that wouldn't help you. If I was
you, I would try to solve the problem in another way.
> The database schema has only 4 tables and 3 of
> them foreign key to a master table. Right now to manage memory I have
> defined a maximum number of rows for the master table, and when
> removing a row I cascade the delete to the other tables.
Instead of using a database, could you use a SoftReference or
WeakReference hash map? Or an LRU map or set (it's easy, just extend
LinkedHashMap or LinkedHashSet)?
> Does H2 have the ability to configure a maximum memory footprint for
> an in-memory DB?
No.
Regards,
Thomas