Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible memory leak in rocksdb_iter_key_string #58

Open
adsk-nns opened this issue Sep 11, 2024 · 0 comments
Open

Possible memory leak in rocksdb_iter_key_string #58

adsk-nns opened this issue Sep 11, 2024 · 0 comments

Comments

@adsk-nns
Copy link

Hello,

I use the following code to enumerate all keys in my database. These keys are ASCII strings, either hashes or simple words such as "meta0", "meta1", etc.

public IEnumerable<string> KVGetKeys()
{
    using var iter = _rocksDb.NewIterator();

    var keys = new HashSet<string>();
    iter.SeekToFirst();
    while (iter.Valid())
    {
        keys.Add(iter.StringKey());
        iter.Next();
    }

    return keys;
}

I then enumerate over the returned set while removing some entries from the database. I do this to remove any entries present which I no longer want to keep. I've noticed steady memory growth, and it looks like more Strings are allocated in memory but never freed by the .NET GC.

If I use the following code, any strings created from the byte[] of Key() are freed up and I no longer see any lasting memory growth.

public IEnumerable<string> KVGetKeys()
{
    using var iter = _rocksDb.NewIterator();

    var keys = new HashSet<string>();
    iter.SeekToFirst();
    while (iter.Valid())
    {
        keys.Add(Encoding.ASCII.GetString(iter.Key()));
        iter.Next();
    }

    return keys;
}

Is there something I may have missed? Or are strings allocated by rocksdb_iter_key_string, which iter.StringKey() calls, potentially leaking memory?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant