Skip to content

Memory leak with a simple Cache using only weak keys and weak values #167

@lauredogit

Description

@lauredogit

Hi,

When using a simple Cache built only specifying .weakKeys() and .weakValues() where keys and values are maintained by other data structures using strong refereneces and maintaining their own lifecycle, we observed a memory leak in production with Caffeine whilst not having observed it with Guava.

With this configuration, we are using the BoundedLocalCache with a LocalCacheFactory.WI and are creating NodeFactory.WW Nodes.

In the WW Node, there is a WeakValueReference which stores a strong reference to the key.

This strong reference caused a memory leak occupying 2/3 of the heap.

We did not setup a Cache#cleanUp task as we expected our cache to be sufficiently accessed to perform its maintenance tasks without it.

The Cache gets about 11 writes per second in production of mainly unique keys, i.e we are using it as a Store, not as a Cache.

I guess our use case does not really fit in and that we need to schedule the cleanUp of the Cache every now and then.

If you need additional details, feel free to ask.

Best regards,
Dominique

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions