Skip to content

[BUG] Memory usage grows continuously #2619

@jjb-pro

Description

@jjb-pro

I have an application (newest LiteDB version) where I never close my LiteDatabase instance because I need continuous read access:

public ILiteCollection<EmailMessage> Messages { get; } 

// ctor: 
Messages = _db.GetCollection<EmailMessage>("messages");

When changing folders in the UI, I query messages like this:

return _repository.Messages
    .Find(m => m.AccountId == Folder.Folder.AccountId && m.FolderPath == Folder.Folder.Path)
    .OrderByDescending(m => m.DateSent);

The following problems arise:

  • LiteDB internal objects (pages, cache, etc.) continuously grow in memory.
  • Memory usage can reach even more than 1 GB.
  • No/very little memory is released while the database remains open.

If I instead open, query, and immediately dispose of the database for each operation, memory is released. There doesn’t seem to be a way to limit LiteDB’s cache when keeping the DB open long-term.

There should be a configurable limit to LiteDB’s internal cache when the DB is kept open. Also, memory should not grow unbounded during read-only access.

This seems like it might be related to the internal page caching system. I’m unsure if the intended usage is to always open/dispose for each query, or if there should be a better way to manage long-lived read-only access.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions