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

Implemented C# GC get heap size/ get used size #208

Merged
merged 8 commits into from
Jul 26, 2023

Conversation

jeanclaudegrenier
Copy link
Collaborator

@jeanclaudegrenier jeanclaudegrenier commented Jul 21, 2023

Would love some input regarding the tests.
They are very approximative, but should be stable. I can't unfortunately check for a precise size, as far as I know.

Edit: turns out they are not as stable as I thought... thanks Yamato 😓 .
Does anyone have a suggestion for a better test?

int[] data = new int[1024 * 1024 * 100];
GC.Collect();
long heapSizeAfterBigAlloc = ClrHost.gc_get_heap_size();
Assert.Greater(heapSizeAfterBigAlloc, heapSize);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try putting GC.KeepAlive(data); at the end of the method.

…mmy data allocated, and that used size is smaller than the total heap
…ified gc_get_used_size to use GC.GetGCMemoryInfo as there seems to be random discrepencies between GC.GetGCMemoryInfo values and GC.GetTotalMemory data (it may also be a race condition issue)
…g triggered)

Removed test to check that used memory is less or equal to total memory, since this is likely to cause instabilities if the GC kicks in between the calls, as it seems like it happened in prior tests.
@jeanclaudegrenier
Copy link
Collaborator Author

Ok finally got everything stable (fingers crossed) tests passed on the last 3 runs (aside from one build timeout, unrelated).

@jeanclaudegrenier jeanclaudegrenier merged commit 699f32c into unity-main Jul 26, 2023
@jeanclaudegrenier jeanclaudegrenier deleted the feature/gc_get_size-to-cs branch July 26, 2023 15:16
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

Successfully merging this pull request may close these issues.

2 participants