SlideShare a Scribd company logo
Problems……..
• Application Crashed
• Application Hanged
• Intermittent Issue
• Services are stopped
• Bad Application Performance
• Time Out Issues
• While running one program another program is crashed
Why This Happens
Memory Leak
“A memory leak is the gradual loss of available
computer memory when a program (an application or part of
the operating system) repeatedly fails to return memory that it has
obtained for temporary use. As a result, the available memory for that
application or that part of the operating system becomes exhausted
and the program can no longer function. For a program that is
frequently opened or called or that runs continuously, even a very
small memory leak can eventually cause the program or the system to
terminate.”
• Make the program smaller
• Get(Allocate) more memory
Which One?
MEMORY MANAGEMENT
What Is Memory Management• “memory management is to provide ways to dynamically allocate portions of memory
to programs at their request, and free it for reuse when no longer needed. ”
How To Avoid Memory Leaks
• Monitor the resource consumption of your application over time
• Handle Memory Management at application side
Best Practices : C#Create only the objects as and when needed and dispose 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 least static variables or instances, if required then too think
twice whether those objects are required in entire lifetime of program
Do not use GC.Collect() manually,(it is bad practice)
Best Practices : C#
Best Practices : Javascript
• “Based on Garbage Collection as in C#”
• 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 array element
• Get default value using ||
Best Practices : Javascript
Best Practices : Python• “Not based on Garbage Collection but it handles memory management”
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 right version
Best Practices : Python
Best Practices : C++“You need to write code about memory management “
Reuse memory ; Try to avoid allocate/deallocate
Use macros instead of small functions
Use int,float instead of char
Try to avoid global variables
Use smart pointers
Use static buffers whenever possible because compiler frees up such kind of
memory automatically
Best Practices : C++
Before writing code Always Ask…
• Is there anything I could be doing more efficiently in my code?
• What (common) optimizations do language engines make?
• What is the language engine unable to optimize for
• Is there anyway I can minify my code?

More Related Content

PPT
Memory management
PDF
Android App Performance
PDF
Hibernate by Jason
PDF
Performance myths in android
PPTX
Asynchronous and parallel programming
PDF
Compute fast of computer
PPT
Op Managerpowerpt
PDF
Memory Management in Trading Platforms
Memory management
Android App Performance
Hibernate by Jason
Performance myths in android
Asynchronous and parallel programming
Compute fast of computer
Op Managerpowerpt
Memory Management in Trading Platforms

Similar to Coding Best Practices For Memory Management (20)

PPTX
Ahieving Performance C#
PPT
CLR Exception Handing And Memory Management
PPTX
Memory profiler and garbage collector in C#
PPTX
Memory management
PPTX
How to do Memory Optimizations in Android
PDF
A New Age of JVM Garbage Collectors (Clojure Conj 2019)
PDF
Rick Blalock: Your Apps are Leaking - Controlling Memory Leaks
PPTX
Exploring .NET memory management - A trip down memory lane - Copenhagen .NET ...
PPTX
ConFoo - Exploring .NET’s memory management – a trip down memory lane
PPTX
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...
PPTX
Cinci ug-january2011-anti-patterns
PDF
Memory Safety with Delphi - Jim McKeeth - Webinar June 2024
PDF
TechGIG_Memory leaks in_java_webnair_26th_july_2012
PPT
3.5 memory and io systems
PDF
Programming for Performance
ODP
Java Garbage Collection, Monitoring, and Tuning
PPTX
DotNetFest - Let’s refresh our memory! Memory management in .NET
PDF
.NET Fest 2018. Maarten Balliauw. Let’s refresh our memory! Memory management...
PDF
Lecture 10 slides (february 4, 2010)
PPTX
Chronicles Of Garbage Collection (GC)
Ahieving Performance C#
CLR Exception Handing And Memory Management
Memory profiler and garbage collector in C#
Memory management
How to do Memory Optimizations in Android
A New Age of JVM Garbage Collectors (Clojure Conj 2019)
Rick Blalock: Your Apps are Leaking - Controlling Memory Leaks
Exploring .NET memory management - A trip down memory lane - Copenhagen .NET ...
ConFoo - Exploring .NET’s memory management – a trip down memory lane
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...
Cinci ug-january2011-anti-patterns
Memory Safety with Delphi - Jim McKeeth - Webinar June 2024
TechGIG_Memory leaks in_java_webnair_26th_july_2012
3.5 memory and io systems
Programming for Performance
Java Garbage Collection, Monitoring, and Tuning
DotNetFest - Let’s refresh our memory! Memory management in .NET
.NET Fest 2018. Maarten Balliauw. Let’s refresh our memory! Memory management...
Lecture 10 slides (february 4, 2010)
Chronicles Of Garbage Collection (GC)
Ad

More from Bhawna Tuteja (6)

PPTX
Basics Of Python Programming
PPTX
The Power Of Full Engagement
PPTX
Git-Basics
PPTX
Six sigma
PPTX
Lean fundamentals
PPTX
How google-tests-software
Basics Of Python Programming
The Power Of Full Engagement
Git-Basics
Six sigma
Lean fundamentals
How google-tests-software
Ad

Recently uploaded (20)

PPT
Introduction Database Management System for Course Database
PDF
Nekopoi APK 2025 free lastest update
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Introduction to Artificial Intelligence
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
ai tools demonstartion for schools and inter college
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Digital Strategies for Manufacturing Companies
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
Introduction Database Management System for Course Database
Nekopoi APK 2025 free lastest update
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Introduction to Artificial Intelligence
Upgrade and Innovation Strategies for SAP ERP Customers
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Computer Software and OS of computer science of grade 11.pptx
wealthsignaloriginal-com-DS-text-... (1).pdf
How to Choose the Right IT Partner for Your Business in Malaysia
ai tools demonstartion for schools and inter college
CHAPTER 2 - PM Management and IT Context
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Digital Strategies for Manufacturing Companies
Odoo Companies in India – Driving Business Transformation.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf

Coding Best Practices For Memory Management

  • 1. Problems…….. • Application Crashed • Application Hanged • Intermittent Issue • Services are stopped • Bad Application Performance • Time Out Issues • While running one program another program is crashed
  • 2. Why This Happens Memory Leak “A memory leak is the gradual loss of available computer memory when a program (an application or part of the operating system) repeatedly fails to return memory that it has obtained for temporary use. As a result, the available memory for that application or that part of the operating system becomes exhausted and the program can no longer function. For a program that is frequently opened or called or that runs continuously, even a very small memory leak can eventually cause the program or the system to terminate.”
  • 3. • Make the program smaller • Get(Allocate) more memory Which One? MEMORY MANAGEMENT
  • 4. What Is Memory Management• “memory management is to provide ways to dynamically allocate portions of memory to programs at their request, and free it for reuse when no longer needed. ”
  • 5. How To Avoid Memory Leaks • Monitor the resource consumption of your application over time • Handle Memory Management at application side
  • 6. Best Practices : C#Create only the objects as and when needed and dispose 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 least static variables or instances, if required then too think twice whether those objects are required in entire lifetime of program Do not use GC.Collect() manually,(it is bad practice)
  • 8. Best Practices : Javascript • “Based on Garbage Collection as in C#” • 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 array element • Get default value using ||
  • 9. Best Practices : Javascript
  • 10. Best Practices : Python• “Not based on Garbage Collection but it handles memory management” 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 right version
  • 12. Best Practices : C++“You need to write code about memory management “ Reuse memory ; Try to avoid allocate/deallocate Use macros instead of small functions Use int,float instead of char Try to avoid global variables Use smart pointers Use static buffers whenever possible because compiler frees up such kind of memory automatically
  • 14. Before writing code Always Ask… • Is there anything I could be doing more efficiently in my code? • What (common) optimizations do language engines make? • What is the language engine unable to optimize for • Is there anyway I can minify my code?