SlideShare una empresa de Scribd logo
1 de 36
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Similar a Managing Memory in Swift (Yes, that's a thing)

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
 
Server’s variations bsw2015
Server’s variations bsw2015Server’s variations bsw2015
Server’s variations bsw2015Laurent Cerveau
 
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
 
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
 

Similar a Managing Memory in Swift (Yes, that's a thing) (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
 
Server’s variations bsw2015
Server’s variations bsw2015Server’s variations bsw2015
Server’s variations bsw2015
 
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 ?
 
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
 

Más 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
 

Más 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

UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDELiveplex
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 

Último (20)

UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
20150722 - AGV
20150722 - AGV20150722 - AGV
20150722 - AGV
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 

Managing Memory in Swift (Yes, that's a thing)

  • 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