Ram counter usage

Dani_S 5,261 Reputation points
2025-09-26T11:40:33.01+00:00

Hi,

Does this code in MAUI app in net 9 can lead to leak memory if not using it , if yes why ?

Thanks,

public MyRootPage() // ctor

{

#if WINDOWS

System.Diagnostics.PerformanceCounter _ramCounter;
```#endif

#if WINDOWS

```sql
    _ramCounter = new System.Diagnostics.PerformanceCounter("Memory", "Available MBytes");
```#endif

}

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

Answer accepted by question author
  1. Bruce (SqlWork.com) 82,146 Reputation points Volunteer Moderator
    2025-09-26T19:59:15.7833333+00:00

    maybe. it won't release its resources until you call .Close() or .Dispose(). as Maui windows don't have a .Dispose event, this is difficult to code correctly. a better option would be to inject a singleton.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.