Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Common memory optimization

What are the most common memory optimizations in csharp, dotnet 2.0. Wanted to see if there common things that people may not be doing by default in winform app

like image 253
leora Avatar asked Dec 18 '22 10:12

leora


2 Answers

  • use structs for small wrapper objects to avoid heap fragmentation
  • think carefully about object lifetimes, especially for large objects so they do not end up on the LOH unless you intend them to
  • think about allocations inside of a loop
  • make sure dynamically sized array will be of reasonable size, otherwise partition the problem
like image 174
Nick Avatar answered Dec 24 '22 00:12

Nick


Use StringBuilder instead of directly modifying a string if you're performing many modifications to the same string.

like image 42
hwiechers Avatar answered Dec 24 '22 01:12

hwiechers