メインコンテンツまでスキップ

Out of Memory issues with C# Extend Apps

Last updated on August 23, 2024
備考

Extend is in Open Beta for AGS Private Cloud! This means that the Extend add-on is available for you to try in your development environment. You can submit your feedback via our Extend Open Beta feedback form.

The .NET C# Extend app uses a garbage collector to automatically manage system memory. However, memory issues may still occur due to:

  • Holding references onto large objects for far longer than necessary
  • Managed memory leaks
  • Unmanaged memory leaks
  • General high memory usage

This article contains best practices and a list of recommended tools to use for efficient memory management and mitigate out of memory (OOM) issues in the local development of your .NET C# Extend app.

Best practices

  1. Use appropriate data type. Using Span<T> wherever possible to reduce the memory usage.

  2. Avoid string concatenation since string is immutable. Use StringBuilder instead.

  3. Limit the amount of data retrieved from other source.

  4. Avoid using unmanaged code. The garbage collector in the .NET C# Extend app does not clean up native resources. Improper implementation of unmanaged code may lead to high memory usage.

To manage your CPU and memory usage, we recommend using the following tools:

Visual Studio

Visual Studio provides great tools to analyze and diagnose memory issues in .NET application.

Image shows Visual Studio diagnostic tools

  1. Debug the .NET C# application using Visual Studio.
  2. On the right sidebar, select Diagnostic Tools and pin it. The total process memory will be shown live.
  3. Go to Memory Usage to take a snapshot and analyze memory usage of your app.

For more information, refer to Visual Studio's official documentation.

Alternatively, you can use Jetbrains Dotmemory to do CPU and memory profiling for .NET applications. For more information, refer to Jetbrains's official documentation.

Dotnet CLI

Dotnet tools allow you to debug memory leaks on Linux and trace high CPU usage.