Memory leaks in Android. Introduction In our day-to da life many apps crash,and the reason one will point to it is memory leak In majority of the cases.

Slides:



Advertisements
Similar presentations
Page-replacement policies On some standard algorithms for the management of resident virtual memory pages.
Advertisements

Paging: Design Issues. Readings r Silbershatz et al: ,
Dr. Fabrizio Gala Dipartimento di Scienze di Base e Applicate Per l’Ingegneria – Sezione di Fisica Via Scarpa Rome, Italy 1.
Operating System Support Focus on Architecture
Chapter 14 Chapter 14: Server Monitoring and Optimization.
Chapter 11 - Monitoring Server Performance1 Ch. 11 – Monitoring Server Performance MIS 431 – created Spring 2006.
Run-Time Storage Organization
5: CPU-Scheduling1 Jerry Breecher OPERATING SYSTEMS SCHEDULING.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 5 Operating Systems.
OPERATING SYSTEMS CPU SCHEDULING.  Introduction to CPU scheduling Introduction to CPU scheduling  Dispatcher Dispatcher  Terms used in CPU scheduling.
Dynamic Memory Allocation Questions answered in this lecture: When is a stack appropriate? When is a heap? What are best-fit, first-fit, worst-fit, and.
INTRODUCTION SOFTWARE HARDWARE DIFFERENCE BETWEEN THE S/W AND H/W.
Storage Management. The stack and the heap Dynamic storage allocation refers to allocating space for variables at run time Most modern languages support.
© 2006, National Research Council Canada © 2006, IBM Corporation Solving performance issues in OTS-based systems Erik Putrycz Software Engineering Group.
Java Example Presentation of a Language. Background Conception: Java began as a language for embedded processors in consumer electronics, such as VCR,
Memory Management in Java Computer Science 3 Gerb Objective: Understand references to composite types in Java.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Beyond Application Profiling to System Aware Analysis Elena Laskavaia, QNX Bill Graham, QNX.
3 Important Performance tracking tools in an Android Application Development Workflow Here are 3 tools every Android application developer should familiarize.
Java Thread Programming
SQL Database Management
Object Lifetime and Pointers
HERON.
Free Transactions with Rio Vista
Threads vs. Events SEDA – An Event Model 5204 – Operating Systems.
Process Management Process Concept Why only the global variables?
EEE Embedded Systems Design Process in Operating Systems 서강대학교 전자공학과
Operating Systems (CS 340 D)
MCTS Guide to Microsoft Windows 7
Chapter 10: Managed Exception Monitoring
Storage Management.
Process Description and Control
Swapping Segmented paging allows us to have non-contiguous allocations
Real-time Software Design
Using Visual Studio with C#
Operating Systems (CS 340 D)
Chapter 6: CPU Scheduling
Capriccio – A Thread Model
Process management Information maintained by OS for process management
Complex Data Types One very important measure of the “goodness” of a PL is the capability of its data types to model the problem space variables Design.
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
PerfView Measure and Improve Your App’s Performance for Free
Adaptive Code Unloading for Resource-Constrained JVMs
Demand Paged Virtual Memory
3: CPU Scheduling Basic Concepts Scheduling Criteria
Closure Representations in Higher-Order Programming Languages
Operating Systems.
Chapter5: CPU Scheduling
Free Transactions with Rio Vista
Chapter 6: CPU Scheduling
CPU SCHEDULING.
HNDIT2417 Mobile Application Development
Testing, debugging, and using support libraries
Chapter 5: CPU Scheduling
Operating System Introduction.
IP Control Gateway (IPCG)
Software - Operating Systems
Chapter 6: CPU Scheduling
Chapter 4: Simulation Designs
Mobile Programming Dr. Mohsin Ali Memon.
Module 5: CPU Scheduling
Chapter 6: CPU Scheduling
Exception Handling.
Classes and Objects Object Creation
Dynamic Binary Translators and Instrumenters
Run-time environments
Module 5: CPU Scheduling
CMSC 202 Constructors Version 9/10.
Presentation transcript:

Memory leaks in Android

Introduction In our day-to da life many apps crash,and the reason one will point to it is memory leak In majority of the cases we see a kind of unpredictable increase in memory usage of app from the time it got started in the foreground and cannot allocate more resources and subsequently leading to a crash. In Java this often results in an OutOfMemoryException being thrown

A memory leak reduces the performance of the android by reducing the amount of available memory. In some of the cases, too much of the available memory may become allocated and all or part of the system or device stops working correctly, the application fails, or the system slows down vastly due to thrashing.

How to fix Memory leak First Step: In the way of fixing a memory leak, we first have to make a deep diagnosis around it.And fortunately we have the Android Studio,which supports a built in tool called Android Monitor and we can use to observe memory usage among other things. All to do is open the Android Monitor and go to the Monitors tab to see how much memory is used and allocated in real time. Any interactions causing resource allocation will be shown here, memory at that particular time,how is engaged will be shown.

The following three things can be known See how your app allocates memory over over time. The Memory Profiler shows a realtime graph of how much memory your app is using, the number allocated Java objects, and when garbage collection occurs. Initiate garbage collection events and take a snapshot of the Java heap while your app runs. Record your app's memory allocations and then inspect all allocated objects, view the stack trace for each allocation, and jump to the corresponding code in the Android Studio editor.

Second Step To avoid running out of memory, you can make the queries to the system to determine how much heap space you have available on the current device. You can query the system for this figure by calling getMemoryInfo(). This returns an ActivityManager.MemoryInfo object that provides information about the device's current memory status, including available memory, total memory, and the memory threshold—the memory level at which the system begins to kill processes. The ActivityManager.MemoryInfo object also exposes a simple boolean, lowMemory that tells you whether the device is running low on memory

Third step Neglected a service running when it’s not needed is one of the worst careless memory-management mistakes an Android app can undergo. If your app needs a service to perform work in the background, do not keep it running unless it needs to run a job. Remember to stop your service when it has completed its task. Otherwise, you can inadvertently cause a memory leak. When you start a service, the system prefers to always keep the process for that service running. This behavior makes services processes very expensive because the RAM used by a service remains unavailable to other processes. This reduces the number of cached processes that the system can keep in the LRU cache, making app switching less efficient.

You should generally avoid use of persistent services because of the on- going demands they place on available memory. Instead, we recommend that you use an alternative implementation such as JobScheduler. For more information about how to use JobScheduler to schedule background processes, see Background Optimizations.

For more information please visit android training in bangaloreandroid training in bangalore

THANKYOU