-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Description
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?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels