Skip to content

Rfc2898DeriveBytes severe memory spike on Android #102406

@borrrden

Description

@borrrden

Description

Using any form of Rfc2898DeriveBytes on .NET Android results in a severe memory spike that gets worse with each call. Here is the obnoxious part: It only happens with release builds (AOT enabled) on an aarch64 emulator (M2 mac). I don't have an aarch64 device to try to see how it compares. Debug builds don't show this behavior, and neither debug nor release appears to show this behavior on x86_64 emulators.

I see an almost instant jump of nearly 300 MiB of RAM. I have some tests that repeatedly call Rfc2898DeriveBytes to derive a password using PBKDF2, and the tests often die because the OS kills it due to memory pressure. I do not see this spike when running the same tests on Windows.

The odd part is that after the tests finish running the memory instantly goes back down to normal. It is reported by dumpsys meminfo as "Lost RAM" while the tests are running.

Steps

I will work on getting a project, but all I need to do to trigger the problem is call Rfc2898DeriveBytes.Pbkdf2("foo", Enumerable.Repeat((byte)1, 16).ToArray(), 64000, HashAlgorithmName.SHA, 32); in fairly rapid succession.

Configuration

I tried both 8.0.105 and 8.0.300 .NET. Built on macOS 14 M2 mac (arm64) and executed on a vanilla emulator with 1GiB of memory and 1 GiB SD card.

Regression?

I am not sure about this since I only recently started running on M2. x86_64 never did, and still does not, show the issue.

Data

I'm happy to gather any data that I can but I'm lost as to how to do it on Android.

Analysis

Without data I am unable to reason about any of this. All I can see is what I get out of dumpsys meminfo and the fact that my tests crash in xharness.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions