Objective-C Memory Management Essentials
eBook - ePub

Objective-C Memory Management Essentials

  1. 200 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Objective-C Memory Management Essentials

About this book

About This Book

  • Learn about the concepts of memory management in Objective-C
  • Get introduced to Swift, an innovative new programming language for Cocoa and Cocoa Touch
  • A step-by-step approach to various memory management techniques with lots of sample code and Xcode projects for your reference

Who This Book Is For

If you are new to Objective-C or a veteran in iOS application development, this is the book for you. This book will ensure that you can actively learn the methods and concepts in relation to memory management in a more engaging way. Basic knowledge of iOS development is required for this book.

Tools to learn more effectively

Saving Books

Saving Books

Keyword Search

Keyword Search

Annotating Text

Annotating Text

Listen to it instead

Listen to it instead

Information

Objective-C Memory Management Essentials


Table of Contents

Objective-C Memory Management Essentials
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Introduction to Objective-C Memory Management
Why do we need memory management in Objective-C?
An object's ownership and life cycle
Ownership of object and reference counting
What's a memory leak and why pay attention to it?
What is an object within Objective-C?
Summary
2. Automatic Reference Counting
What is ARC and how does it work?
How ARC looks
Project settings for ARC
A memory model in Objective-C
What you need to know about ARC and weak references
Summary
3. Using Autorelease Pools
Understanding the autorelease pool mechanism
Autorelease pool mechanism
Reducing peak memory footprint with autorelease pool blocks
An overview of Apple autoreleased classes
NSRunLoop
NSException
ARC and autorelease
Autorelease pool blocks and threads
Summary
4. Object Creation and Storage
Creation and initialization of objects
What is a class?
Classes
Object immutability
Object mutability
Inheritance
Convenience initializers
An Objective-C programmer's responsibility
The singleton pattern
Creating @property
Creating custom methods
String formatting
Summary
5. Managing Your Application Data
Device memory
Image optimization
Lazy loading
Control creation
Caching
SDWebImage
Object serialization
SQLite
SQLite versus Core Data
Summary
6. Using Core Data for Persistence
Why use Core Data?
Understanding Core Data concepts
Putting it into practice
Getting into the code
Saving data into the persistent store
Deleting data from the persistent store
Updating data
Summary
7. Key-value Programming Approaches
What is key-value coding or KVC?
The NSKeyValueCoding protocol
Compliance of attributes and one-to-one relationships
Compliance of indexed one-to-many relationships
Compliance of unordered many-to-many relationships
Advantages of key-value coding
Disadvantages of key-value coding
Manual subsets of NSKeyValueCoding behavior
Advantages of creating your own lookup path
Disadvantages of creating your own lookup path
Associated objects
Advantages of using associated objects
Disadvantages of using associated objects
Selectors as keys
Advantages of using selectors as keys
Disadvantages of using selectors as keys
Maximum flexibility and handling unusual keys/values
Advantages of doing your own implementation
Disadvantages of doing your own implementation
Key-value observing
Implementing key-value observing
Performance considerations
Summary
8. Introduction to Swift
Welcome to Swift
Basics of Swift
Variable declaration
Iterating statements
Conditional statements
Functions
Classes and structures in Swift
Closures
Memory management in Swift
Summary
9. Memory Management and Debugging
Memory leaks
Strong/weak references
Retain cycles
Memory overuse
Using the debugger and breakpoints
Collecting data on your app
Plumbing memory leaks
Using the LLVM / Clang Static Analyzer
Using NSZombie
Summary
10. Tips and Tricks for Memory Management
Objective-C, C, and memory management
Getters and setters
The property attribute in Objective-C
Performance guidelines
Don't overthink about memory management
When to avoid KVC and KVO
Summary
11. Features of Xcode 6
Introducing Xcode 6
What's new in storyboard
Allowing storyboard or the NIB file to replace launch images
Launching images from your app
Universal storyboards
Debugging in Xcode 6
Debug gauges
What's new in Interface Builder
Playground for Swift
Summary
Index

Objective-C Memory Management Essentials

Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: March 2015
Production reference: 1190315
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-84969-712-5
www.packtpub.com

Credits

Authors
Gibson Tang
Maxim Vasilkov
Reviewers
Emil Atanasov
Christine M. Gerpheide
Commissioning Editor
James Jones
Acquisition Editor
James Jones
Content Development Editor
Amey Varangaonkar
Technical Editor
Vijin Boricha
Copy Editor
Janbal Dharmaraj
Project Coordinator
Leena Purkait
Proofreaders
Simran Bhogal
Maria Gould
Indexer
Hemangini Bari
Graphics
Sheetal Aute
Production Coordinator
Melwyn D'sa
Cover Work
Melwyn D'sa

About the Authors

Gibson Tang grew up loving technology after getting his hands on an old Apple II when he was still a young kid. Since then, he has never stopped keeping pace with technology, and after he coded his first "Hello World" program, he has been hooked on programming ever since.
Following his studies at Nanyang Polytechnic and Singapore Institute of Management and serving a 6-year stint in the Republic of Singapore Navy (RSN), he honed his development skills creating software and games for Yahoo! and other Fortune 500 companies. In 2010, he founded Azukisoft Pte Ltd in Singapore to focus on mobile application development. Since then, he has developed countless mobile applications and games for start-ups and big companies both in USA and Singapore.
Apart from programming, he indulges in various hobbies such as soccer, computer games, and jogging in order to get his regular dose of Vitamin D and to see the sun once in a while. Occasionally, he would be on Steam or Battle.net blowing off some steam by slaying monsters and killer robots after a day of programming.

Table of contents

  1. Objective-C Memory Management Essentials

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Objective-C Memory Management Essentials by Gibson Tang, Maxim Vasilkov in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming. We have over one million books available in our catalogue for you to explore.