Many of these don't really optimize memory...
- Dispose an object after use or make it null. Always
Dispose()
an object if it is IDisposable
. This COULD save you memory problems, but not necessarily. (Also, use Using
if possible)
- Use try/finally or using block.
try/finally
- This is similar to Using
for objects that aren't IDisposable
(I find them to be messy, so I prefer this solution.)
- Use GC.Collect() if required. I wouldn't really be able to ever recommend
GC.Collect()
. Normally the GC
will do a better job on knowing when to collect something than you will.
- Remove unnecessary object initialization. This one can definately help. If your code is going around creating objects that aren't needed... then this could waste some space. This can be sorta allievated/masked with Lazy Initialization.
- Manage Image caching. This is VERY vague... but yes... its important to manage how many images you have stored in memory. It may not always be desirable to keep images in memory... It can open the door to paging for other processes in your code that are more critical.
- Manage BLOB data, Memory stream and file stream I think this is similar to #5.