Introduction
As a software engineer, we see the below kinds of problems on a daily basis while developing/testing any application.
- Application Crashed
- Application Hanged
- Intermittent Issue
- Services are stopped
- Bad Application Performance
- Time Out Issues
- While running one program another program is crashed
Have
we ever thought why these occur? The major root cause of all the above problems
is memory management/handling is not done properly in the application. Here are a few tips(coding) suggested by experts for memory management/handling in any application
Best Practices in C#
- Create only the objects as and when needed and dispose of it after use.
- Decide the scope for each variable and object, if they are required inside methods declare them inside those methods, do not make them private
- Use the IDisposable interfaces on your custom objects and release all the resources(if any), un-register from all the events, etc
- Use ‘using’ if you are working with MemoryStream
- Use less static variables or instances, and if required too, think twice whether those objects are required in the entire lifetime of the program
- Do not use GC.Collect()manually. (It is a bad practice)
Best Practices: Javascript
- Always
keep browser extension update
- Use Array Filter
- Use static buffers wherever possible. The compiler automatically frees such memory.
- Previously allocated memory should be manually freed after it is no longer required.
- Use ~~ instead of math functions
- For emptying and array use length
- Merge array using push instead of concat
- Use splice to delete an array element
- Get default value using ||
Best Practices: Python
- Use Slots for your objects
- Interning: Beware of Interned Strings!
- Use Format Instead of ‘+’ for Generating Strings
- Use Modules
- Use built-in functions wherever possible:
- Use Multiprocessing not multithreading
- Design and Data Structure
- Pick the right version