SlideShare uma empresa Scribd logo
1 de 36
Baixar para ler offline
Managing Memory in Swift
(Yes, that's a thing)
Swift Cloud Workshop 2 Austin, TX

30 September 2017
Illustration
Renders
by
https://pixabay.com/en/users/3dman_eu-1553824/
@CarlBrwn
Managing Memory in Swift
(Yes, that's a thing)
Swift Cloud Workshop 2 Austin, TX

30 September 2017
Illustration
Renders
by
https://pixabay.com/en/users/3dman_eu-1553824/
@CarlBrwn
Obligatory Bio
• Swift on the Server Developer at IBM

• First iOS App in 2008, many projects since

• Author, App Accomplished

• Meetup Organizer 

• SwiftAustin & CocoaCoders

• Parent
@CarlBrwn
Is Swift on the Server READY?
• In my (personal) Opinion, [NOT speaking
on behalf of IBM], this answer depends
on two things:

1. Do you need the ecosystem to have
more features that you can build
yourself?
in the Cloud
[For your app?]
@CarlBrwn
Tale of Two Ecosystems
• NPM Claims 475,000 available node.js
packages.

• IBM’s Swift Package Catalog has 4000 entries
(last I looked), and that number includes at
least some iOS-only packages.

• So if you want to do Server-Side Swift, be
prepared to roll your own. 

• Personally, I’m okay with writing my own
left-pad, but YMMV.
@CarlBrwn
Is Swift on the Server READY?
• In my (personal) Opinion, [NOT speaking
on behalf of IBM], this answer depends
on two things:

1. Do you need the ecosystem to have
more features that you can build
yourself?

2. Can you manage your own memory?
in the Cloud
[For your app?]
@CarlBrwn
Previously on
“Conferences
with Carl”:
try!Swift NYC 2017
• This talk expands on that talk

• It should be up on video at
Realm sometime soon

• Not necessary to have seen it
@CarlBrwn
0
35
70
105
140
PR Fixes
CodeOrdering Counting Encapsulation Logic(App) Memory
Naming Optionals Performance Threading Typing
Unclear
PRs Meeting Criteria (502 total)
?
Today’s Talk
@CarlBrwn
Memory (6.4%)
• Most people I talk to don’t think of Swift
Memory Management as a problem

• Some of the Apple folks I talked to
about it at WWDC this year were
surprised, too (at first)

• It is a real problem, and it’s serious

• And it’s worse on Linux…

• For 3 primary reasons:
@CarlBrwn
Reason 1: Duration
• Cloud apps run longer (in general)

• Cloud apps can’t restart themselves in
the background while you’re checking
Facebook

• Memory leaks are cumulative

• Cloud costs scale with dedicated RAM
@CarlBrwn
Reason 2: Tools
• We don’t have Xcode

• We don’t have Instruments

• We don’t have cycle detectors

• In fact, we don’t have any Swift-aware
memory diagnostics on Linux at all
@CarlBrwn
Reason 3: Structure
• iOS (and Mac) Apps have a Structure:

• Application Delegate

• View Controllers

• Views

• Well-tested clean-up code

• (e.g. Views reclaimed when removed from
the screen)

• By contrast, Linux has: main

• Biggest problem w/Swift on Linux (IMNSHO)
@CarlBrwn
BRIEF Intro to ARC
• Automatic Reference Counting

• In the Old Days (2009), we would call
retain, release or autorelease on each
object by hand

• Apple published rules about when you were
supposed to use each

• Apple wrote an Analyzer tool that would tell
you when you broke the rules

• ARC does for you what those rules said to do
1/6
@CarlBrwn
BRIEF Intro to ARC
• Each object has a counter

• (Originally this was part of the NSObject implementation, but now
it applies to more things, but I’m probably still going to say “object”
today)

• When you take a reference to something (like
putting it in an ivar), you increment its counter

• When you’re done with it (or the system is done
with you), its counter is decremented

• The object only knows its count. It has no idea
who is pointing at it.
2/6
@CarlBrwn
BRIEF Intro to ARC
• ARC keeps things around as long as their
reference counts are greater than zero

• When a counter drops to zero, the object is
available to be reclaimed

• Reclamation happens periodically and
deterministically, but not necessarily
instantly
3/6
@CarlBrwn
BRIEF Intro to ARC
• When an object is reclaimed, all the things
it’s referencing have their counts reduced
by one

• That often causes those things to get
reclaimed in turn, and so on

• Unlike GC, no marking or sweeping is
needed during reclamation

• The system doesn’t need to pause the
whole system to free up memory
RAM
ARC
Object
4/6
@CarlBrwn
ARC-Optimized Architecture
This is the world ARC wants (and expects)
5/6
BRIEF Intro to ARC
@CarlBrwn
BRIEF Intro to ARC
• When two things refer to each other, ARC is
powerless

• Neither count will ever be set to zero

• The objects can never be reclaimed

• Some Garbage Collectors in Other Languages
can find and reclaim these kinds of cycles at
runtime (with a performance penalty), but in
Swift it’s not happening

• If no other objects can reach either of these, you
get a classic leak
6/6
@CarlBrwn
Good Structures
• Clear lines of ownership

• Clear relationships & hierarchies

• Tend to use ivars/properties

• Tend not to remember things passed in
from outside (especially from caller)

• Tend to reinforce existing relationships
& events

• e.g. Memory gets naturally
reclaimed when views leave the
screen or network connections drop
@CarlBrwn
Bad Structures
• Tangled or unclear relationships

• Strong references to things passed in
from outside

• Things captured in closures

• Hierarchies not rooted in natural
events

• e.g. Needs clean up
functions instead of it
“just happening”

• “Missed Dominos”
@CarlBrwn
You have to Measure
• This is a necessary step - you can’t reliably quantify
memory issues from reading code (if you can, you
should be mining bitcoin in your head)

• This has to happen at runtime, static analysis won’t
help

• You need either a production-like synthetic load, or
to measure in actual production (or both)

• Honestly, I don’t think many people do this (even for
iOS)
@CarlBrwn
My Measuring Scripts are Available
https://github.com/carlbrown/SwiftServerComparison
May or may not work for your use-case, but you’re welcome to them
@CarlBrwn
Wish there was a better way
Run long test,
grab `ps` logs,
graph
Rollback,
Next or
Fixed?
Test with `heaptrack`
to find next
Area of interest
Change code
@CarlBrwn
Graph of RSS from `ps aux`
Moving the slope, One little fix at a time
@CarlBrwn
Variability can be a Problem
Hard to see the leak (signal) when leak is small compared to the spread (noise)

This was happening because of clean-up functions

As you run the test longer, it becomes less of an issue@CarlBrwn
Duration
This is a half hour run
@CarlBrwn
Duration (cont)
Same run, full duration (~5 hours)
@CarlBrwn
Wish there was a better way
Run long test,
grab `ps` logs,
graph
Rollback,
Next or
Fixed?
Test with `heaptrack`
to find next
Area of interest
@CarlBrwn
Darwin’s cool tools aren’t for you…
Nothing remotely like it on Linux

Even if you test on Darwin, there may still be Linux leaks
@CarlBrwn
…And that’s a real shame
Because the leaks that happen when you don’t have an 

App Delegate structure can get REALLY convoluted
@CarlBrwn
Use heaptrack & heaptrack_gui
Not constrained to single thread like valgrind

But no awareness of Swift reference counts or structure
@CarlBrwn
Wish there was a better way
Run long test,
grab `ps` logs,
graph
Rollback,
Next or
Fixed?
Test with `heaptrack`
to find next
Area of interest
Change code
@CarlBrwn
So what code do you change?
• heaptrack only gives us the line of code that allocated the object
that is “stuck" in memory (& you may want to run swift-demangle)

• Find all the places that object is used and especially all the times it’s
passed to a closure or as an argument 

• See if you can make them weak without crashing (or unowned, but
only if you have to - it’s not safe)

• See if making it weak at that point changes the slope of the graph

• Make only one change at a time, and measure

• Continue until you’ve found the right place(s) to make weak

• NOTE: This will only work if ownership is clear. If not, refactor
Good Question
@CarlBrwn
Most of my changes turn out to be dead-ends
The ones that make the slope better get merged to `master`
@CarlBrwn
Thank You
& Good Luck
@CarlBrwn
Thank You
& Good Luck
@CarlBrwn

Mais conteúdo relacionado

Mais procurados

Method Swizzling with Objective-C
Method Swizzling with Objective-CMethod Swizzling with Objective-C
Method Swizzling with Objective-CAdamFallon4
 
Reactive Streams, j.u.concurrent & Beyond!
Reactive Streams, j.u.concurrent & Beyond!Reactive Streams, j.u.concurrent & Beyond!
Reactive Streams, j.u.concurrent & Beyond!Konrad Malawski
 
CQRS Evolved - CQRS + Akka.NET
CQRS Evolved - CQRS + Akka.NETCQRS Evolved - CQRS + Akka.NET
CQRS Evolved - CQRS + Akka.NETDavid Hoerster
 
Reactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaReactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaNexThoughts Technologies
 
Not Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabsNot Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabsKonrad Malawski
 
Getting Deep on Orchestration - Nickoloff - DockerCon16
Getting Deep on Orchestration - Nickoloff - DockerCon16Getting Deep on Orchestration - Nickoloff - DockerCon16
Getting Deep on Orchestration - Nickoloff - DockerCon16allingeek
 
How Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM EcosystemHow Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM EcosystemKonrad Malawski
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprisesMike Slinn
 
Erlang as a cloud citizen, a fractal approach to throughput
Erlang as a cloud citizen, a fractal approach to throughputErlang as a cloud citizen, a fractal approach to throughput
Erlang as a cloud citizen, a fractal approach to throughputPaolo Negri
 
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...Konrad Malawski
 
The magic of (data parallel) distributed systems and where it all breaks - Re...
The magic of (data parallel) distributed systems and where it all breaks - Re...The magic of (data parallel) distributed systems and where it all breaks - Re...
The magic of (data parallel) distributed systems and where it all breaks - Re...Holden Karau
 
FunctionalConf '16 Robert Virding Erlang Ecosystem
FunctionalConf '16 Robert Virding Erlang EcosystemFunctionalConf '16 Robert Virding Erlang Ecosystem
FunctionalConf '16 Robert Virding Erlang EcosystemRobert Virding
 
Serverless observability - a hero's perspective
Serverless observability - a hero's perspectiveServerless observability - a hero's perspective
Serverless observability - a hero's perspectiveYan Cui
 
DEF CON 27 - CHRISTOPHER ROBERTS - firmware slap
DEF CON 27 - CHRISTOPHER ROBERTS - firmware slapDEF CON 27 - CHRISTOPHER ROBERTS - firmware slap
DEF CON 27 - CHRISTOPHER ROBERTS - firmware slapFelipe Prado
 
Springone2gx 2015 Reactive Options for Groovy
Springone2gx 2015  Reactive Options for GroovySpringone2gx 2015  Reactive Options for Groovy
Springone2gx 2015 Reactive Options for GroovySteve Pember
 
Infinum Android Talks #05 - Square tape
Infinum Android Talks #05 - Square tapeInfinum Android Talks #05 - Square tape
Infinum Android Talks #05 - Square tapeInfinum
 

Mais procurados (20)

Method Swizzling with Objective-C
Method Swizzling with Objective-CMethod Swizzling with Objective-C
Method Swizzling with Objective-C
 
Reactive Streams, j.u.concurrent & Beyond!
Reactive Streams, j.u.concurrent & Beyond!Reactive Streams, j.u.concurrent & Beyond!
Reactive Streams, j.u.concurrent & Beyond!
 
Training – Going Async
Training – Going AsyncTraining – Going Async
Training – Going Async
 
CQRS Evolved - CQRS + Akka.NET
CQRS Evolved - CQRS + Akka.NETCQRS Evolved - CQRS + Akka.NET
CQRS Evolved - CQRS + Akka.NET
 
Reactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaReactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJava
 
Not Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabsNot Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabs
 
Mini training - Reactive Extensions (Rx)
Mini training - Reactive Extensions (Rx)Mini training - Reactive Extensions (Rx)
Mini training - Reactive Extensions (Rx)
 
Getting Deep on Orchestration - Nickoloff - DockerCon16
Getting Deep on Orchestration - Nickoloff - DockerCon16Getting Deep on Orchestration - Nickoloff - DockerCon16
Getting Deep on Orchestration - Nickoloff - DockerCon16
 
How Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM EcosystemHow Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM Ecosystem
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprises
 
Erlang as a cloud citizen, a fractal approach to throughput
Erlang as a cloud citizen, a fractal approach to throughputErlang as a cloud citizen, a fractal approach to throughput
Erlang as a cloud citizen, a fractal approach to throughput
 
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
 
Training - What is Performance ?
Training  - What is Performance ?Training  - What is Performance ?
Training - What is Performance ?
 
The magic of (data parallel) distributed systems and where it all breaks - Re...
The magic of (data parallel) distributed systems and where it all breaks - Re...The magic of (data parallel) distributed systems and where it all breaks - Re...
The magic of (data parallel) distributed systems and where it all breaks - Re...
 
FunctionalConf '16 Robert Virding Erlang Ecosystem
FunctionalConf '16 Robert Virding Erlang EcosystemFunctionalConf '16 Robert Virding Erlang Ecosystem
FunctionalConf '16 Robert Virding Erlang Ecosystem
 
Serverless observability - a hero's perspective
Serverless observability - a hero's perspectiveServerless observability - a hero's perspective
Serverless observability - a hero's perspective
 
DEF CON 27 - CHRISTOPHER ROBERTS - firmware slap
DEF CON 27 - CHRISTOPHER ROBERTS - firmware slapDEF CON 27 - CHRISTOPHER ROBERTS - firmware slap
DEF CON 27 - CHRISTOPHER ROBERTS - firmware slap
 
Springone2gx 2015 Reactive Options for Groovy
Springone2gx 2015  Reactive Options for GroovySpringone2gx 2015  Reactive Options for Groovy
Springone2gx 2015 Reactive Options for Groovy
 
Migrating big data
Migrating big dataMigrating big data
Migrating big data
 
Infinum Android Talks #05 - Square tape
Infinum Android Talks #05 - Square tapeInfinum Android Talks #05 - Square tape
Infinum Android Talks #05 - Square tape
 

Semelhante a Managing Memory in Swift

Chronicles Of Garbage Collection (GC)
Chronicles Of Garbage Collection (GC)Chronicles Of Garbage Collection (GC)
Chronicles Of Garbage Collection (GC)Techizzaa
 
Solving k8s persistent workloads using k8s DevOps style
Solving k8s persistent workloads using k8s DevOps styleSolving k8s persistent workloads using k8s DevOps style
Solving k8s persistent workloads using k8s DevOps styleMayaData
 
Building Big Data Streaming Architectures
Building Big Data Streaming ArchitecturesBuilding Big Data Streaming Architectures
Building Big Data Streaming ArchitecturesDavid Martínez Rego
 
12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQL12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQLKonstantin Gredeskoul
 
Architecture by Accident
Architecture by AccidentArchitecture by Accident
Architecture by AccidentGleicon Moraes
 
DefCore: The Interoperability Standard for OpenStack
DefCore: The Interoperability Standard for OpenStackDefCore: The Interoperability Standard for OpenStack
DefCore: The Interoperability Standard for OpenStackMark Voelker
 
Comment choisir entre Parse, Heroku et AWS ?
Comment choisir entre Parse, Heroku et AWS ?Comment choisir entre Parse, Heroku et AWS ?
Comment choisir entre Parse, Heroku et AWS ?TheFamily
 
Server’s variations bsw2015
Server’s variations bsw2015Server’s variations bsw2015
Server’s variations bsw2015Laurent Cerveau
 
Dapper: the microORM that will change your life
Dapper: the microORM that will change your lifeDapper: the microORM that will change your life
Dapper: the microORM that will change your lifeDavide Mauri
 
Container Attached Storage with OpenEBS - CNCF Paris Meetup
Container Attached Storage with OpenEBS - CNCF Paris MeetupContainer Attached Storage with OpenEBS - CNCF Paris Meetup
Container Attached Storage with OpenEBS - CNCF Paris MeetupMayaData Inc
 
The Economies of Scaling Software
The Economies of Scaling SoftwareThe Economies of Scaling Software
The Economies of Scaling SoftwareAbdelmonaim Remani
 
Agile Data: Building Hadoop Analytics Applications
Agile Data: Building Hadoop Analytics ApplicationsAgile Data: Building Hadoop Analytics Applications
Agile Data: Building Hadoop Analytics ApplicationsDataWorks Summit
 
The economies of scaling software - Abdel Remani
The economies of scaling software - Abdel RemaniThe economies of scaling software - Abdel Remani
The economies of scaling software - Abdel Remanijaxconf
 
Exploring .NET memory management (iSense)
Exploring .NET memory management (iSense)Exploring .NET memory management (iSense)
Exploring .NET memory management (iSense)Maarten Balliauw
 
The Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidThe Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidStanojko Markovik
 
Using the big guns: Advanced OS performance tools for troubleshooting databas...
Using the big guns: Advanced OS performance tools for troubleshooting databas...Using the big guns: Advanced OS performance tools for troubleshooting databas...
Using the big guns: Advanced OS performance tools for troubleshooting databas...Nikolay Savvinov
 
Memory Management In Python The Basics
Memory Management In Python The BasicsMemory Management In Python The Basics
Memory Management In Python The BasicsNina Zakharenko
 
A tale of two proxies
A tale of two proxiesA tale of two proxies
A tale of two proxiesSensePost
 
RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015Ben Lesh
 

Semelhante a Managing Memory in Swift (20)

Chronicles Of Garbage Collection (GC)
Chronicles Of Garbage Collection (GC)Chronicles Of Garbage Collection (GC)
Chronicles Of Garbage Collection (GC)
 
Solving k8s persistent workloads using k8s DevOps style
Solving k8s persistent workloads using k8s DevOps styleSolving k8s persistent workloads using k8s DevOps style
Solving k8s persistent workloads using k8s DevOps style
 
Building Big Data Streaming Architectures
Building Big Data Streaming ArchitecturesBuilding Big Data Streaming Architectures
Building Big Data Streaming Architectures
 
Perl in Teh Cloud
Perl in Teh CloudPerl in Teh Cloud
Perl in Teh Cloud
 
12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQL12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQL
 
Architecture by Accident
Architecture by AccidentArchitecture by Accident
Architecture by Accident
 
DefCore: The Interoperability Standard for OpenStack
DefCore: The Interoperability Standard for OpenStackDefCore: The Interoperability Standard for OpenStack
DefCore: The Interoperability Standard for OpenStack
 
Comment choisir entre Parse, Heroku et AWS ?
Comment choisir entre Parse, Heroku et AWS ?Comment choisir entre Parse, Heroku et AWS ?
Comment choisir entre Parse, Heroku et AWS ?
 
Server’s variations bsw2015
Server’s variations bsw2015Server’s variations bsw2015
Server’s variations bsw2015
 
Dapper: the microORM that will change your life
Dapper: the microORM that will change your lifeDapper: the microORM that will change your life
Dapper: the microORM that will change your life
 
Container Attached Storage with OpenEBS - CNCF Paris Meetup
Container Attached Storage with OpenEBS - CNCF Paris MeetupContainer Attached Storage with OpenEBS - CNCF Paris Meetup
Container Attached Storage with OpenEBS - CNCF Paris Meetup
 
The Economies of Scaling Software
The Economies of Scaling SoftwareThe Economies of Scaling Software
The Economies of Scaling Software
 
Agile Data: Building Hadoop Analytics Applications
Agile Data: Building Hadoop Analytics ApplicationsAgile Data: Building Hadoop Analytics Applications
Agile Data: Building Hadoop Analytics Applications
 
The economies of scaling software - Abdel Remani
The economies of scaling software - Abdel RemaniThe economies of scaling software - Abdel Remani
The economies of scaling software - Abdel Remani
 
Exploring .NET memory management (iSense)
Exploring .NET memory management (iSense)Exploring .NET memory management (iSense)
Exploring .NET memory management (iSense)
 
The Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidThe Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with android
 
Using the big guns: Advanced OS performance tools for troubleshooting databas...
Using the big guns: Advanced OS performance tools for troubleshooting databas...Using the big guns: Advanced OS performance tools for troubleshooting databas...
Using the big guns: Advanced OS performance tools for troubleshooting databas...
 
Memory Management In Python The Basics
Memory Management In Python The BasicsMemory Management In Python The Basics
Memory Management In Python The Basics
 
A tale of two proxies
A tale of two proxiesA tale of two proxies
A tale of two proxies
 
RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015
 

Mais de Carl Brown

GDPR, User Data, Privacy, and Your Apps
GDPR, User Data, Privacy, and Your AppsGDPR, User Data, Privacy, and Your Apps
GDPR, User Data, Privacy, and Your AppsCarl Brown
 
New in iOS 11.3b4 and Xcode 9.3b4
New in iOS 11.3b4 and Xcode 9.3b4New in iOS 11.3b4 and Xcode 9.3b4
New in iOS 11.3b4 and Xcode 9.3b4Carl Brown
 
Better Swift from the Foundation up #tryswiftnyc17 09-06
Better Swift from the Foundation up #tryswiftnyc17 09-06Better Swift from the Foundation up #tryswiftnyc17 09-06
Better Swift from the Foundation up #tryswiftnyc17 09-06Carl Brown
 
Generics, the Swift ABI and you
Generics, the Swift ABI and youGenerics, the Swift ABI and you
Generics, the Swift ABI and youCarl Brown
 
Swift GUI Development without Xcode
Swift GUI Development without XcodeSwift GUI Development without Xcode
Swift GUI Development without XcodeCarl Brown
 
what's new in iOS10 2016-06-23
what's new in iOS10 2016-06-23what's new in iOS10 2016-06-23
what's new in iOS10 2016-06-23Carl Brown
 
Open Source Swift: Up and Running
Open Source Swift: Up and RunningOpen Source Swift: Up and Running
Open Source Swift: Up and RunningCarl Brown
 
Parse migration CocoaCoders April 28th, 2016
Parse migration CocoaCoders April 28th, 2016Parse migration CocoaCoders April 28th, 2016
Parse migration CocoaCoders April 28th, 2016Carl Brown
 
Swift 2.2 Design Patterns CocoaConf Austin 2016
Swift 2.2 Design Patterns CocoaConf Austin 2016Swift 2.2 Design Patterns CocoaConf Austin 2016
Swift 2.2 Design Patterns CocoaConf Austin 2016Carl Brown
 
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...Carl Brown
 
Cocoa coders 141113-watch
Cocoa coders 141113-watchCocoa coders 141113-watch
Cocoa coders 141113-watchCarl Brown
 
iOS8 and the new App Store
iOS8 and the new App Store   iOS8 and the new App Store
iOS8 and the new App Store Carl Brown
 
Dark Art of Software Estimation 360iDev2014
Dark Art of Software Estimation 360iDev2014Dark Art of Software Estimation 360iDev2014
Dark Art of Software Estimation 360iDev2014Carl Brown
 
Intro to cloud kit Cocoader.org 24 July 2014
Intro to cloud kit   Cocoader.org 24 July 2014Intro to cloud kit   Cocoader.org 24 July 2014
Intro to cloud kit Cocoader.org 24 July 2014Carl Brown
 
Welcome to Swift (CocoaCoder 6/12/14)
Welcome to Swift (CocoaCoder 6/12/14)Welcome to Swift (CocoaCoder 6/12/14)
Welcome to Swift (CocoaCoder 6/12/14)Carl Brown
 
Writing Apps that Can See: Getting Data from CoreImage to Computer Vision - ...
Writing Apps that Can See: Getting Data from CoreImage to Computer  Vision - ...Writing Apps that Can See: Getting Data from CoreImage to Computer  Vision - ...
Writing Apps that Can See: Getting Data from CoreImage to Computer Vision - ...Carl Brown
 
Introduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsIntroduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsCarl Brown
 
REST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A TourREST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A TourCarl Brown
 
360iDev iOS AntiPatterns
360iDev iOS AntiPatterns360iDev iOS AntiPatterns
360iDev iOS AntiPatternsCarl Brown
 

Mais de Carl Brown (20)

GDPR, User Data, Privacy, and Your Apps
GDPR, User Data, Privacy, and Your AppsGDPR, User Data, Privacy, and Your Apps
GDPR, User Data, Privacy, and Your Apps
 
New in iOS 11.3b4 and Xcode 9.3b4
New in iOS 11.3b4 and Xcode 9.3b4New in iOS 11.3b4 and Xcode 9.3b4
New in iOS 11.3b4 and Xcode 9.3b4
 
Better Swift from the Foundation up #tryswiftnyc17 09-06
Better Swift from the Foundation up #tryswiftnyc17 09-06Better Swift from the Foundation up #tryswiftnyc17 09-06
Better Swift from the Foundation up #tryswiftnyc17 09-06
 
Generics, the Swift ABI and you
Generics, the Swift ABI and youGenerics, the Swift ABI and you
Generics, the Swift ABI and you
 
Swift GUI Development without Xcode
Swift GUI Development without XcodeSwift GUI Development without Xcode
Swift GUI Development without Xcode
 
what's new in iOS10 2016-06-23
what's new in iOS10 2016-06-23what's new in iOS10 2016-06-23
what's new in iOS10 2016-06-23
 
Open Source Swift: Up and Running
Open Source Swift: Up and RunningOpen Source Swift: Up and Running
Open Source Swift: Up and Running
 
Parse migration CocoaCoders April 28th, 2016
Parse migration CocoaCoders April 28th, 2016Parse migration CocoaCoders April 28th, 2016
Parse migration CocoaCoders April 28th, 2016
 
Swift 2.2 Design Patterns CocoaConf Austin 2016
Swift 2.2 Design Patterns CocoaConf Austin 2016Swift 2.2 Design Patterns CocoaConf Austin 2016
Swift 2.2 Design Patterns CocoaConf Austin 2016
 
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
 
Gcd cc-150205
Gcd cc-150205Gcd cc-150205
Gcd cc-150205
 
Cocoa coders 141113-watch
Cocoa coders 141113-watchCocoa coders 141113-watch
Cocoa coders 141113-watch
 
iOS8 and the new App Store
iOS8 and the new App Store   iOS8 and the new App Store
iOS8 and the new App Store
 
Dark Art of Software Estimation 360iDev2014
Dark Art of Software Estimation 360iDev2014Dark Art of Software Estimation 360iDev2014
Dark Art of Software Estimation 360iDev2014
 
Intro to cloud kit Cocoader.org 24 July 2014
Intro to cloud kit   Cocoader.org 24 July 2014Intro to cloud kit   Cocoader.org 24 July 2014
Intro to cloud kit Cocoader.org 24 July 2014
 
Welcome to Swift (CocoaCoder 6/12/14)
Welcome to Swift (CocoaCoder 6/12/14)Welcome to Swift (CocoaCoder 6/12/14)
Welcome to Swift (CocoaCoder 6/12/14)
 
Writing Apps that Can See: Getting Data from CoreImage to Computer Vision - ...
Writing Apps that Can See: Getting Data from CoreImage to Computer  Vision - ...Writing Apps that Can See: Getting Data from CoreImage to Computer  Vision - ...
Writing Apps that Can See: Getting Data from CoreImage to Computer Vision - ...
 
Introduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsIntroduction to Git Commands and Concepts
Introduction to Git Commands and Concepts
 
REST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A TourREST/JSON/CoreData Example Code - A Tour
REST/JSON/CoreData Example Code - A Tour
 
360iDev iOS AntiPatterns
360iDev iOS AntiPatterns360iDev iOS AntiPatterns
360iDev iOS AntiPatterns
 

Último

Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Último (20)

Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

Managing Memory in Swift

  • 1. Managing Memory in Swift (Yes, that's a thing) Swift Cloud Workshop 2 Austin, TX 30 September 2017 Illustration Renders by https://pixabay.com/en/users/3dman_eu-1553824/ @CarlBrwn
  • 2. Managing Memory in Swift (Yes, that's a thing) Swift Cloud Workshop 2 Austin, TX 30 September 2017 Illustration Renders by https://pixabay.com/en/users/3dman_eu-1553824/ @CarlBrwn
  • 3. Obligatory Bio • Swift on the Server Developer at IBM • First iOS App in 2008, many projects since • Author, App Accomplished • Meetup Organizer • SwiftAustin & CocoaCoders • Parent @CarlBrwn
  • 4. Is Swift on the Server READY? • In my (personal) Opinion, [NOT speaking on behalf of IBM], this answer depends on two things: 1. Do you need the ecosystem to have more features that you can build yourself? in the Cloud [For your app?] @CarlBrwn
  • 5. Tale of Two Ecosystems • NPM Claims 475,000 available node.js packages. • IBM’s Swift Package Catalog has 4000 entries (last I looked), and that number includes at least some iOS-only packages. • So if you want to do Server-Side Swift, be prepared to roll your own. • Personally, I’m okay with writing my own left-pad, but YMMV. @CarlBrwn
  • 6. Is Swift on the Server READY? • In my (personal) Opinion, [NOT speaking on behalf of IBM], this answer depends on two things: 1. Do you need the ecosystem to have more features that you can build yourself? 2. Can you manage your own memory? in the Cloud [For your app?] @CarlBrwn
  • 7. Previously on “Conferences with Carl”: try!Swift NYC 2017 • This talk expands on that talk • It should be up on video at Realm sometime soon • Not necessary to have seen it @CarlBrwn
  • 8. 0 35 70 105 140 PR Fixes CodeOrdering Counting Encapsulation Logic(App) Memory Naming Optionals Performance Threading Typing Unclear PRs Meeting Criteria (502 total) ? Today’s Talk @CarlBrwn
  • 9. Memory (6.4%) • Most people I talk to don’t think of Swift Memory Management as a problem • Some of the Apple folks I talked to about it at WWDC this year were surprised, too (at first) • It is a real problem, and it’s serious • And it’s worse on Linux… • For 3 primary reasons: @CarlBrwn
  • 10. Reason 1: Duration • Cloud apps run longer (in general) • Cloud apps can’t restart themselves in the background while you’re checking Facebook • Memory leaks are cumulative • Cloud costs scale with dedicated RAM @CarlBrwn
  • 11. Reason 2: Tools • We don’t have Xcode • We don’t have Instruments • We don’t have cycle detectors • In fact, we don’t have any Swift-aware memory diagnostics on Linux at all @CarlBrwn
  • 12. Reason 3: Structure • iOS (and Mac) Apps have a Structure: • Application Delegate • View Controllers • Views • Well-tested clean-up code • (e.g. Views reclaimed when removed from the screen) • By contrast, Linux has: main • Biggest problem w/Swift on Linux (IMNSHO) @CarlBrwn
  • 13. BRIEF Intro to ARC • Automatic Reference Counting • In the Old Days (2009), we would call retain, release or autorelease on each object by hand • Apple published rules about when you were supposed to use each • Apple wrote an Analyzer tool that would tell you when you broke the rules • ARC does for you what those rules said to do 1/6 @CarlBrwn
  • 14. BRIEF Intro to ARC • Each object has a counter • (Originally this was part of the NSObject implementation, but now it applies to more things, but I’m probably still going to say “object” today) • When you take a reference to something (like putting it in an ivar), you increment its counter • When you’re done with it (or the system is done with you), its counter is decremented • The object only knows its count. It has no idea who is pointing at it. 2/6 @CarlBrwn
  • 15. BRIEF Intro to ARC • ARC keeps things around as long as their reference counts are greater than zero • When a counter drops to zero, the object is available to be reclaimed • Reclamation happens periodically and deterministically, but not necessarily instantly 3/6 @CarlBrwn
  • 16. BRIEF Intro to ARC • When an object is reclaimed, all the things it’s referencing have their counts reduced by one • That often causes those things to get reclaimed in turn, and so on • Unlike GC, no marking or sweeping is needed during reclamation • The system doesn’t need to pause the whole system to free up memory RAM ARC Object 4/6 @CarlBrwn
  • 17. ARC-Optimized Architecture This is the world ARC wants (and expects) 5/6 BRIEF Intro to ARC @CarlBrwn
  • 18. BRIEF Intro to ARC • When two things refer to each other, ARC is powerless • Neither count will ever be set to zero • The objects can never be reclaimed • Some Garbage Collectors in Other Languages can find and reclaim these kinds of cycles at runtime (with a performance penalty), but in Swift it’s not happening • If no other objects can reach either of these, you get a classic leak 6/6 @CarlBrwn
  • 19. Good Structures • Clear lines of ownership • Clear relationships & hierarchies • Tend to use ivars/properties • Tend not to remember things passed in from outside (especially from caller) • Tend to reinforce existing relationships & events • e.g. Memory gets naturally reclaimed when views leave the screen or network connections drop @CarlBrwn
  • 20. Bad Structures • Tangled or unclear relationships • Strong references to things passed in from outside • Things captured in closures • Hierarchies not rooted in natural events • e.g. Needs clean up functions instead of it “just happening” • “Missed Dominos” @CarlBrwn
  • 21. You have to Measure • This is a necessary step - you can’t reliably quantify memory issues from reading code (if you can, you should be mining bitcoin in your head) • This has to happen at runtime, static analysis won’t help • You need either a production-like synthetic load, or to measure in actual production (or both) • Honestly, I don’t think many people do this (even for iOS) @CarlBrwn
  • 22. My Measuring Scripts are Available https://github.com/carlbrown/SwiftServerComparison May or may not work for your use-case, but you’re welcome to them @CarlBrwn
  • 23. Wish there was a better way Run long test, grab `ps` logs, graph Rollback, Next or Fixed? Test with `heaptrack` to find next Area of interest Change code @CarlBrwn
  • 24. Graph of RSS from `ps aux` Moving the slope, One little fix at a time @CarlBrwn
  • 25. Variability can be a Problem Hard to see the leak (signal) when leak is small compared to the spread (noise) This was happening because of clean-up functions As you run the test longer, it becomes less of an issue@CarlBrwn
  • 26. Duration This is a half hour run @CarlBrwn
  • 27. Duration (cont) Same run, full duration (~5 hours) @CarlBrwn
  • 28. Wish there was a better way Run long test, grab `ps` logs, graph Rollback, Next or Fixed? Test with `heaptrack` to find next Area of interest @CarlBrwn
  • 29. Darwin’s cool tools aren’t for you… Nothing remotely like it on Linux Even if you test on Darwin, there may still be Linux leaks @CarlBrwn
  • 30. …And that’s a real shame Because the leaks that happen when you don’t have an App Delegate structure can get REALLY convoluted @CarlBrwn
  • 31. Use heaptrack & heaptrack_gui Not constrained to single thread like valgrind But no awareness of Swift reference counts or structure @CarlBrwn
  • 32. Wish there was a better way Run long test, grab `ps` logs, graph Rollback, Next or Fixed? Test with `heaptrack` to find next Area of interest Change code @CarlBrwn
  • 33. So what code do you change? • heaptrack only gives us the line of code that allocated the object that is “stuck" in memory (& you may want to run swift-demangle) • Find all the places that object is used and especially all the times it’s passed to a closure or as an argument • See if you can make them weak without crashing (or unowned, but only if you have to - it’s not safe) • See if making it weak at that point changes the slope of the graph • Make only one change at a time, and measure • Continue until you’ve found the right place(s) to make weak • NOTE: This will only work if ownership is clear. If not, refactor Good Question @CarlBrwn
  • 34. Most of my changes turn out to be dead-ends The ones that make the slope better get merged to `master` @CarlBrwn
  • 35. Thank You & Good Luck @CarlBrwn
  • 36. Thank You & Good Luck @CarlBrwn