ANDROID
PERFORMANCE
TUNING
MEMORY
SERGII KOZYREV
Senior	SE
22.06.2016
Memory
Garbage Collector is such a cool
feature
There is always taxes -
“performance is not free”? :)
Understanding memory
•GC
•Find	objects	that	can’t	be	accessed	
•Reclaim	the	resources
•Questions:
•Heap	vs	Stack	memory?
•What	GC	collects?
•How	leaks	happens?
Concerns
Memory Leaks
•It’s	not	only	about	OutOfMemoryError
•It	reduces	available	memory	and	causes	GC	run	more	frequent	- which	is	
bad
Different VMs – different Logs
•Dalvik (every	GC)
•ART	(if	the	GC	pause	exceeds	
than	5ms	or	the	GC	duration	
exceeds	100ms)
Concurrent VS	Alloc
DEMO Memory Monitor
Memory Leaks
•Simple	- “handler	case”,	or	every	circular	referenced	objects
•Complex	- holding	a	handle	to	the	ClassLoader objects,	load	
in	onCreate and	don’t	check	if	classes	already	loaded	(no	
class	unload	procedure)
Memory Leaks
•Static	Activities,	Views,	Context	aware	stuff
•Inner	Classes
•Anonymous	Classes
•Handlers
•Threads	and	TimerTask
•Sensor	Manager
DEMO HeapViewver
Move allocations out of inner loops
:)
DEMO Allocation Tracker
Thank You!
Links:
https://github.com/kozyrevsergey89/PerformanceLab
https://github.com/square/leakcanary
https://www.udacity.com/course/android-performance--ud825