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

fixed image nativearray deallocation when entry is set back to cold pool #214

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pfcDorn
Copy link

@pfcDorn pfcDorn commented Jul 17, 2024

I found out that each AsyncReadback Entry will be deallocated when it's moved back to the cold pool. Which results in unnecessary memory allocation and deallocation. So i made some changes which only results in recreation when the required nativearray length has changed.
I also added automatic deallocation for staled entries which are not used for more than 3 seconds for lower memory consumption. In case of unexptected app stuttering, interruptions and so on.

@keijiro keijiro self-assigned this Jul 17, 2024
@keijiro
Copy link
Owner

keijiro commented Jul 17, 2024

Thanks for the PR. I'll consider merging it in future updates.

@hybridherbst hybridherbst force-pushed the fix/asyncreadback-deallocation-optimization branch from 929ce39 to e69e173 Compare September 12, 2024 07:46
@@ -59,11 +62,21 @@ public Interop.FourCC FourCC

public void Allocate(int width, int height, bool alpha, string metadata)
{
_lastUsedTime = DateTime.Now;

Choose a reason for hiding this comment

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

DateTime.Now is not monotonic, so should only be used for user-visible timestamps.
It can go backwards and often doesn't advance at 1 second per second.

Consider using Unity's Time.unscaledTime or Time.realtimeSinceStartup or System.Diagnostics.Stopwatch

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.

3 participants