Skip to content

Memory leak in ValueTask.AsAsync() #15

@mvkara

Description

@mvkara

Memory leak is in the ContinueWith() section with the captured lambda parameter (despite the use of the wildcard) or the task being captured longer than it is needed.

When in use with a recursive async where it does a ValueTask/Task conversion, looks at the result and potentially recurses the action in the ContinueWith block appears effectively for the lifetime of the loop at times. This could be the life of the whole program as the Action may never return meaning the task's result is held in memory by this ContinueWith function. If the async is recursive and runs this over and over this could result in all task results remaining in memory. Switching to old fashioned Async.AwaitTask when awaiting the task in the async loop fixes the issue.

I think that the Infrastructures.asAsyncV function retains the object when memory profiling. Could be the wildcard arg, or the task object itself. I found this when profiling, tough leak to spot.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy