ITP 342 Advanced Mobile App Dev. Memory
|
|
- Ashlie Bell
- 6 years ago
- Views:
Transcription
1 ITP 342 Advanced Mobile App Dev Memory
2 Memory Management Objective-C provides two methods of application memory management. 1. In the method described in this guide, referred to as manual retain-release or MRR, you explicitly manage memory by keeping track of objects you own. This is implemented using a model, known as reference counting, that the Foundation class NSObject provides in conjunction with the runtime environment. 2. In Automatic Reference Counting, or ARC, the system uses the same reference counting system as MRR, but it inserts the appropriate memory management method calls for you at compile-time. You are strongly encouraged to use ARC for new projects. If you use ARC, there is typically no need to understand the underlying implementation, although it may in some situations be helpful. 2
3 Memory Management Policy Application memory management is the process of allocating memory during your program s runtime, using it, and freeing it when you are done with it. A well-written program uses as little memory as possible. In Objective-C, it can also be seen as a way of distributing ownership of limited memory resources among many pieces of data and code. Although memory management is typically considered at the level of an individual object, your goal is actually to manage object graphs. You want to make sure that you have no more objects in memory than you actually need. 3
4 4
5 Memory Management Policy The basic model used for memory management in a reference-counted environment is provided by a combination of methods defined in the NSObject protocol and a standard method naming convention. The NSObject class also defines a method, dealloc, that is invoked automatically when an object is deallocated. 5
6 Basic Memory Management Rules The memory management model is based on object ownership. Any object may have one or more owners. As long as an object has at least one owner, it continues to exist. If an object has no owners, the runtime system destroys it automatically. 6
7 Cocoa's Policies You own any object you create You create an object using a method whose name begins with alloc, new, copy, or mutablecopy You can take ownership of an object using retain A received object is normally guaranteed to remain valid within the method it was received in, and that method may also safely return the object to its invoker. When you no longer need it, you must relinquish ownership of an object you own You relinquish ownership of an object by sending it a release message or an autorelease message. You must not relinquish ownership of an object you do not own This is just corollary of the previous policy rules, stated explicitly. 7
8 Simple Example The Person object is created using the alloc method, so it is subsequently sent a release message when it is no longer needed. The person s name is not retrieved using any of the owning methods, so it is not sent a release message. { } Person *aperson = [[Person alloc] init]; //... NSString *name = aperson.fullname; //... [aperson release]; 8
9 Send a Deferred Release You use autorelease when you need to send a deferred release message typically when returning an object from a method. You own the string returned by alloc. To abide by the memory management rules, you must relinquish ownership of the string before you lose the reference to it. If you use release, however, the string will be deallocated before it is returned (and the method would return an invalid object). Using autorelease, you signify that you want to relinquish ownership, but you allow the caller of the method to use the returned string before it is deallocated. - (NSString *)fullname { NSString *string = [[[NSString alloc] initwithformat:@"%@ %@", self.firstname, self.lastname] autorelease]; return string; } 9
10 Example You could also implement the fullname method like this: - (NSString *)fullname { NSString *string = [NSString stringwithformat:@"%@ %@", self.firstname, self.lastname]; return string; } Following the basic rules, you don t own the string returned by stringwithformat:, so you can safely return the string from the method. 10
11 Objects Returned by Reference You don't own objects returned by reference Some methods in Cocoa specify that an object is returned by reference (that is, they take an argument of type ClassName ** or id *). A common pattern is to use an NSError object that contains information about an error if one occurs. You do not create the NSError object, so you do not own it. There is no need to release it. NSString *filename = <#Get a file name#>; NSError *error; NSString *string = [[NSString alloc] initwithcontentsoffile:filename encoding:nsutf8stringencoding error:&error]; if (string == nil) { // Deal with error... } //... [string release]; 11
12 Relinquish Ownership of Objects The NSObject class defines a method, dealloc, that is invoked automatically when an object has no owners and its memory is reclaimed in Cocoa terminology it is freed or deallocated. The role of the dealloc method is to free the object's own memory, and to dispose of any resources it holds, including ownership of any object instance variables. 12
13 Example of Person : (retain) NSString (retain) NSString (assign, readonly) Person //... - (void)dealloc [_firstname release]; [_lastname release]; [super dealloc]; Never invoke another object s dealloc method directly. You must invoke the superclass s implementation at the end of your implementation. 13
14 Core Foundation Core Foundation uses similar but different rules There are similar memory management rules for Core Foundation objects /CoreFoundation/Conceptual/CFMemoryMgmt/CFMe morymgmt.html#//apple_ref/doc/uid/ i The naming conventions for Cocoa and Core Foundation, however, are different. In particular, Core Foundation s Create Rule does not apply to methods that return Objective-C objects. 14
15 Practical Memory Management Use accessor methods to make memory management easier Use accessor methods to set property values Don t use accessor methods in initializer methods and dealloc Use weak references to avoid retain cycles Avoid causing deallocation of objects you re using Don t use dealloc to manage scarce resources Collections own the objects they contain Ownership policy is implemented using retain counts 15
16 Ownership Policy The ownership policy is implemented through reference counting typically called retain count after the retain method. Each object has a retain count. When you create an object, it has a retain count of 1. When you send an object a retain message, its retain count is incremented by 1. When you send an object a release message, its retain count is decremented by 1. When you send an object a autorelease message, its retain count is decremented by 1 at the end of the current autorelease pool block. If an object s retain count is reduced to zero, it is deallocated. 16
17 MRR Summary Basically works like this: If you need to keep an object around you need to retain it, unless it already was retained for you. If you want to stop using an object you need to release it, unless it was already released for you (with autorelease). The principles of manual memory management aren t hard but it s very easy to make a mistake, and these small mistakes can have dire consequences. Either your app will crash at some point because you ve released an object too often and your variables are pointing at data that is no longer valid, or you ll run out of memory because you don t release objects enough and they stick around forever. The static analyzer from Xcode is a great help in finding these kinds of problems but ARC goes a step further. 17
18 ARC ARC is a feature of the LLVM 3.0 compiler and it completely does away with the manual memory management that all ios developers love to hate. Using ARC in your own projects is extremely simple. You keep programming as usual, except that you no longer call retain, release and autorelease. With Automatic Reference Counting enabled, the compiler will automatically insert retain, release and autorelease in the correct places in your program. You no longer have to worry about any of this, because the compiler does it for you. 18
19 ARC It is important to realize that ARC is a feature of the Objective-C compiler and therefore all the ARC stuff happens when you build your app. ARC is not a runtime feature (except for one small part, the weak pointer system), nor is it *garbage collection* that you may know from other languages. All that ARC does is insert retains and releases into your code when it compiles it, exactly where you would have or at least should have put them yourself. That makes ARC just as fast as manually managed code, and sometimes even a bit faster because it can perform certain optimizations under the hood. 19
20 Pointers Keep Objects Alive The new rules you have to learn for ARC are quite simple. With manual memory management you needed to retain an object to keep it alive. That is no longer necessary, all you have to do is make a pointer to the object. As long as there is a variable pointing to an object, that object stays in memory. When the pointer gets a new value or ceases to exist, the associated object is released. This is true for all variables: instance variables, synthesized properties, and even local variables. 20
21 ARC Limitations Automatic Reference Counting also has a few limitations. For starters, ARC only works on Objective-C objects. If your app uses Core Foundation or malloc() and free(), then you re still responsible for doing the memory management there. In addition, certain language rules have been made stricter in order to make sure ARC can always do its job properly. 21
22 ARC Just because ARC takes care of doing retain and release for you in the proper places, doesn t mean you can completely forget about memory management altogether. Because strong pointers keep objects alive, there are still situations where you will need to set these pointers to nil by hand, or your app might run out of available memory. If you keep holding on to all the objects you ve ever created, then ARC will never be able to release them. Therefore, whenever you create a new object, you still need to think about who owns it and how long the object should stay in existence. 22
23 Automatic Conversion There are three things you can do to make your app ARC-compatible: 1. Xcode has an automatic conversion tool that can migrate your source files. 2. You can convert the files by hand. 3. You can disable ARC for source files that you do not want to convert. This is useful for third-party libraries that you don t feel like messing with. 23
24 Switch to ARC ARC is a feature of the new LLVM 3.0 compiler. Your existing projects most likely use the older GCC 4.2 or LLVM-GCC compilers, so it s a good idea to switch the project to the new compiler first and see if it compiles cleanly in non-arc mode. Go to the Project Settings screen, select the Artists target and under Build Settings type compiler into the search box. This will filter the list to bring up just the compiler options Click on the Compiler for C/C++/Objective-C option to change it to Apple LLVM compiler
25 Switch to ARC Still in the Build Settings screen, switch to All to see all the available settings (instead of Basic, which only shows the most-often used settings). Search for automatic and set the Objective-C Automatic Reference Counting option to Yes. This is a project-wide flag that tells Xcode that you wish to compile all of the source files in your project using the ARC compiler. From Xcode s menu, choose Edit\Refactor\Convert to Objective-C ARC. 25
26 Review of Properties Properties manage an object s internal data A property s data is stored in an instance variable or ivar Xcode generated these variables automatically The property accesses the ivar via getter/setter methods (aka accessors) in front of the declaration of the ivar We access properties using the self keyword 26
27 Encapsulation Getter and setter methods Prevent direct access to object data Allow a class to respond to data changes Enable inheritance and overriding Properties Provide automatic encapsulation Enable Key-Value Observing in Cocoa Manage Memory why-user-getters-and-setters 27
28 Placement Put in the interface file (.h) to make them public to other classes // USCViewController : In the class extension in the implementation file (.m) // USCViewController 28
29 Examples // Primitive type, read-write by int age; // Primitive type, (readonly) BOOL canlegallyvote; // (weak, nonatomic) IBOutlet UITextField (weak, nonatomic) IBOutlet UILabel *messagelabel; // (strong, nonatomic) NSString *name; // Objects, create only a (readonly) UIView *rootview; 29
30 Property (strong, nonatomic) NSDate *launchtime; Memory Properties Readable Properties Method Name Properties Threading Properties strong weak copy assign readonly readwrite getter setter nonatomic atomic Setter retains the new value (default under ARC) Assignment doesn't affect object's lifespan Setter makes a copy of the new value For primitives (preceded weak for objects) Only a getter is generated Getter and setter methods generated (default) The method name used for the getter The method name used for the setter Doesn't ensure multi-thread safety of get/set Makes get/set multi-thread safe (default) 30
31 Attributes IBOutlets (Interface Builder components) Use (weak, nonatomic) Class ivars (instance variables) Use (strong, nonatomic) for mobile // (weak, nonatomic) IBOutlet UITextField (weak, nonatomic) IBOutlet UILabel *messagelabel; // (strong, nonatomic) NSString (strong, nonatomic) NSDate *launchtime; 31
32 Weak References Retaining an object creates a strong reference to that object. An object cannot be deallocated until all of its strong references are released. A problem, known as a retain cycle, can therefore arise if two objects may have cyclical references that is, they have a strong reference to each other (either directly, or through a chain of other objects each with a strong reference to the next leading back to the first). 32
33 Example The Document object has a Page object for each page in the document. Each Page object has a property that keeps track of which document it is in. If the Document object has a strong reference to the Page object and the Page object has a strong reference to the Document object, neither object can ever be deallocated. The Document s reference count cannot become zero until the Page object is released, and the Page object won t be released until the Document object is deallocated. 33
34 Example The solution to the problem of retain cycles is to use weak references. A weak reference is a non-owning relationship where the source object does not retain the object to which it has a reference. To keep the object graph intact, however, there must be strong references somewhere (if there were only weak references, then the pages and paragraphs might not have any owners and so would be deallocated). Cocoa establishes a convention, therefore, that a parent object should maintain strong references to its children, and that the children should have weak references to their parents. 34
35 Memory Management Efficient memory management is an important aspect of writing high performance code in both OS X and ios. Minimizing memory usage not only decreases your application s memory footprint, it can also reduce the amount of CPU time it consumes. Both OS X and ios include a fully-integrated virtual memory system that you cannot turn off; it is always on. Both systems also provide up to 4 gigabytes of addressable space per 32-bit process. 35
36 Virtual Memory System In iphone applications, read-only data that is already on the disk (such as code pages) is simply removed from memory and reloaded from disk as needed. Writable data is never removed from memory by the operating system. Instead, if the amount of free memory drops below a certain threshold, the system asks the running applications to free up memory voluntarily to make room for new data. Applications that fail to free up enough memory are terminated. 36
37 Tips for Allocating Memory Memory is an important resource for your application so it s important to think about how your application will use memory and what might be the most efficient allocation approaches. Most applications do not need to do anything special; they can simply allocate objects or memory blocks as needed and not see any performance degradation. For applications that use large amount of memory, however, carefully planning out your memory allocation strategy could make a big difference. 37
38 Improve Memory-Related Performance Besides allocating the right amount of memory for a given operation, there are other ways to improve the efficiency of your program's memory usage. Tips: Defer your memory allocations Initialize memory block efficiently Reuse temporary memory buffers Free unused memory 38
39 Good Practices Prevent Problems There are two main kinds of problems that result from incorrect memory management: Freeing or overwriting data that is still in use This causes memory corruption, and typically results in your application crashing, or worse, corrupted user data. Not freeing data that is no longer in use causes memory leaks A memory leak is where allocated memory is not freed, even though it is never used again. Leaks cause your application to use ever-increasing amounts of memory, which in turn may result in poor system performance or your application being terminated. 39
40 Good Practices Prevent Problems Thinking about memory management from the perspective of reference counting, however, is frequently counterproductive, because you tend to consider memory management in terms of the implementation details rather than in terms of your actual goals. Instead, you should think of memory management from the perspective of object ownership and object graphs. Cocoa uses a straightforward naming convention to indicate when you own an object returned by a method. 40
41 Resources /general/conceptual/devpediacocoacore/memorymanagement.html /Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.h tml n/performance/conceptual/managingmemory/articles/ MemoryAlloc.html 41
ITP 342 Mobile App Dev. Fundamentals
ITP 342 Mobile App Dev Fundamentals Objective-C Classes Encapsulate data with the methods that operate on that data An object is a runtime instance of a class Contains its own in-memory copy of the instance
More informationAnnouncement. Final Project Proposal Presentations and Updates
Announcement Start Final Project Pitches on Wednesday Presentation slides dues by Tuesday at 11:59 PM Email slides to cse438ta@gmail.com Extensible Networking Platform 1 1 - CSE 438 Mobile Application
More informationDesign Phase. Create a class Person. Determine the superclass. NSObject (in this case)
Design Phase Create a class Person Determine the superclass NSObject (in this case) 8 Design Phase Create a class Person Determine the superclass NSObject (in this case) What properties should it have?
More informationCS193P - Lecture 3. iphone Application Development. Custom Classes Object Lifecycle Autorelease Properties
CS193P - Lecture 3 iphone Application Development Custom Classes Object Lifecycle Autorelease Properties 1 Announcements Assignments 1A and 1B due Wednesday 1/13 at 11:59 PM Enrolled Stanford students
More informationMobile Application Development
Mobile Application Development Lecture 13 Introduction to ObjectiveC Part II 2013/2014 Parma Università degli Studi di Parma Lecture Summary Object creation Memory management Automatic Reference Counting
More informationCS193E Lecture #3 Categories and Protocols Cocoa Memory Management
CS193E Lecture #3 Categories and Protocols Cocoa Memory Management Winter 2008, Dempsey/Marcos 1 Today s Topics Questions from Assignment 1A or 1B? Categories Protocols Cocoa Memory Management Object life
More informationOVERVIEW. Why learn ios programming? Share first-hand experience. Identify platform differences. Identify similarities with.net
OVERVIEW Why learn ios programming? Share first-hand experience. Identify platform differences. Identify similarities with.net Microsoft MVP for 4 years C#, WinForms, WPF, Silverlight Joined Cynergy about
More informationMobile Application Programming. Objective-C Classes
Mobile Application Programming Objective-C Classes Custom Classes @interface Car : NSObject #import Car.h + (int) viper; - (id) initwithmodel:(int)m; @implementation Car Point position; float velocity;
More informationMobile Application Programming. Memory Management
Mobile Application Programming Memory Management Memory Management Ownership Model Memory Management in Objective-C is based on an ownership model. Objects may have many owners. Actions that result in
More informationITP 342 Advanced Mobile App Dev. Memory
ITP 342 Advanced Mobile App Dev Memory Memory Management Swift uses Automatic Reference Counting (ARC) to track and manage your app's memory usage. In most cases, this means that memory management just
More informationObjective-C and COCOA Applications
Objective-C and COCOA Applications Fall, 2012 Prof. Massimiliano "Max" Pala pala@nyu.edu Overview X-Code IDE Basics Objective-C Classes Methods Invocations Important Types Memory Management Protocols Exceptions
More informationios: Objective-C Primer
ios: Objective-C Primer Jp LaFond Jp.LaFond+e76@gmail.com TF, CS76 Announcements n-puzzle feedback this week (if not already returned) ios Setup project released Android Student Choice project due Tonight
More informationIPHONE DEVELOPMENT. Getting Started with the iphone SDK
IPHONE DEVELOPMENT Getting Started with the iphone SDK OBJECTIVE-C The Big Picture STRICT SUPERSET OF C The Objective C Language Any C stuff applies Standard libs are here (time, sqrt etc) The C Language
More informationReview. iphone Application Programming Lecture 2: Objective-C, Cocoa. History. Objective-C. Device restrictions. Interaction paradigm changes
Review iphone Application Programming Lecture 2: Objective-C, Cocoa Device restrictions Gero Herkenrath Media Computing Group RWTH Aachen University Winter Semester 2013/2014 http://hci.rwth-aachen.de/iphone
More informationITP 342 Mobile App Dev. Connections
ITP 342 Mobile App Dev Connections User Interface Interactions First project displayed information to the user, but there was no interaction. We want the users of our app to touch UI components such as
More informationMy First iphone App. 1. Tutorial Overview
My First iphone App 1. Tutorial Overview In this tutorial, you re going to create a very simple application on the iphone or ipod Touch. It has a text field, a label, and a button. You can type your name
More informationObjective-C. Stanford CS193p Fall 2013
New language to learn! Strict superset of C Adds syntax for classes, methods, etc. A few things to think differently about (e.g. properties, dynamic binding) Most important concept to understand today:
More informationObjective-C ICT/7421ICTNathan. René Hexel. School of Information and Communication Technology Griffith University.
Objective-C 2.0 2501ICT/7421ICTNathan René Hexel School of Information and Communication Technology Griffith University Semester 1, 2012 Outline Fast Enumeration and Properties 1 Fast Enumeration and Properties
More informationObjective-C Part 2 (ECS189H) Ken Joy Serban Porumbescu
Objective-C Part 2 (ECS189H) Ken Joy joy@cs.ucdavis.edu Serban Porumbescu porumbes@cs.ucdavis.edu Today Objective-C Memory Management Properties Categories and Protocols Delegates Objective-C Memory Management
More informationContents at a Glance
For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to access them. Contents at a Glance About the Author...
More informationCS193P: HelloPoly Walkthrough
CS193P: HelloPoly Walkthrough Overview The goal of this walkthrough is to give you a fairly step by step path through building a simple Cocoa Touch application. You are encouraged to follow the walkthrough,
More informationCS193p Spring 2010 Thursday, April 29, 2010
CS193p Spring 2010 Announcements You should have received an e-mail by now If you received e-mail approving enrollment, but are not in Axess, do it! If you have any questions, please ask via e-mail or
More informationReview. iphone Application Programming Lecture 2: Objective-C, Cocoa. History. Objective-C. Device restrictions. Interaction paradigm changes
Review iphone Application Programming Lecture 2: Objective-C, Cocoa Device restrictions Gero Herkenrath Media Computing Group RWTH Aachen University Winter Semester 2013/2014 http://hci.rwth-aachen.de/iphone
More informationiphone Programming Patrick H. Madden SUNY Binghamton Computer Science Department
iphone Programming Patrick H. Madden SUNY Binghamton Computer Science Department pmadden@acm.org http://optimal.cs.binghamton.edu General Outline Overview of the tools, and where to get more information
More informationITP 342 Mobile App Dev. Connections
ITP 342 Mobile App Dev Connections User Interface Interactions First project displayed information to the user, but there was no interaction. We want the users of our app to touch UI components such as
More informationYour First iphone Application
Your First iphone Application General 2009-01-06 Apple Inc. 2009 Apple Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form
More informationStanford CS193p. Developing Applications for ios Fall Stanford CS193p. Fall 2013
Developing Applications for ios -14 Today What is this class all about? Description Prerequisites Homework / Final Project ios Overview What s in ios? MVC Object-Oriented Design Concept Objective C (Time
More informationPrinciples of Programming Languages. Objective-C. Joris Kluivers
Principles of Programming Languages Objective-C Joris Kluivers joris.kluivers@gmail.com History... 3 NeXT... 3 Language Syntax... 4 Defining a new class... 4 Object identifiers... 5 Sending messages...
More informationMemory Management: The Details
Lecture 10 Memory Management: The Details Sizing Up Memory Primitive Data Types Complex Data Types byte: char: short: basic value (8 bits) 1 byte 2 bytes Pointer: platform dependent 4 bytes on 32 bit machine
More informationiphone Application Tutorial
iphone Application Tutorial 2008-06-09 Apple Inc. 2008 Apple Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any
More informationYour First iphone OS Application
Your First iphone OS Application General 2010-03-15 Apple Inc. 2010 Apple Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form
More informationAssignment II: Foundation Calculator
Assignment II: Foundation Calculator Objective The goal of this assignment is to extend the CalculatorBrain from last week to allow inputting variables into the expression the user is typing into the calculator.
More informationStructure of Programming Languages Lecture 10
Structure of Programming Languages Lecture 10 CS 6636 4536 Spring 2017 CS 6636 4536 Lecture 10: Classes... 1/23 Spring 2017 1 / 23 Outline 1 1. Types Type Coercion and Conversion Type Classes, Generics,
More informationIntro to Native ios Development. Dave Koziol Arbormoon Software, Inc.
Intro to Native ios Development Dave Koziol Arbormoon Software, Inc. About Me Long time Apple Developer (20 WWDCs) Organizer Ann Arbor CocoaHeads President & ios Developer at Arbormoon Software Inc. Wunder
More informationigc Garbage Collection
igc Garbage Collection User s Manual Harnix Technologies Inc. 2011-08-16 - 2 - Contents Overview... 6 Basic Concepts... 6 Architecture... 7 How the Garbage Collector Works... 7 Enabling Garbage Collection...
More informationiphone App Basics iphone and ipod touch Development Fall 2009 Lecture 5
iphone App Basics iphone and ipod touch Development Fall 2009 Lecture 5 Questions? Announcements Assignment #1 due this evening by 11:59pm Remember, if you wish to use a free late you must email me before
More informationStanford CS193p. Developing Applications for iphone 4, ipod Touch, & ipad Spring Stanford CS193p Spring 2011
Developing Applications for iphone 4, ipod Touch, & ipad Today Dynamic Binding Introspection Foundation Framework Enumeration More Objective-C Allocating and Initializing objects Memory Management Demo
More informationCh. 11: References & the Copy-Constructor. - continued -
Ch. 11: References & the Copy-Constructor - continued - const references When a reference is made const, it means that the object it refers cannot be changed through that reference - it may be changed
More informationIntroductory ios Development
Instructor s Introductory ios Development Unit 3 - Objective-C Classes Introductory ios Development 152-164 Unit 3 - Swift Classes Quick Links & Text References Structs vs. Classes Structs intended for
More informationMy First iphone App (for Xcode version 6.4)
My First iphone App (for Xcode version 6.4) 1. Tutorial Overview In this tutorial, you re going to create a very simple application on the iphone or ipod Touch. It has a text field, a label, and a button
More informationPraktikum Entwicklung von Mediensystemen mit ios
Praktikum Entwicklung von Mediensystemen mit ios SS 2011 Michael Rohs michael.rohs@ifi.lmu.de MHCI Lab, LMU München Milestones 26.5. Project definition, brainstorming, main functions, persona 9.6. (week
More informationThe MVC Design Pattern
The MVC Design Pattern The structure of iphone applications is based on the Model-View-Controller (MVC) design pattern because it benefits object-oriented programs in several ways. MVC based programs tend
More informationthe gamedesigninitiative at cornell university Lecture 9 Memory Management
Lecture 9 Gaming Memory Constraints Redux Wii-U Playstation 4 2GB of RAM 1GB dedicated to OS Shared with GPGPU 8GB of RAM Shared GPU, 8-core CPU OS footprint unknown 2 Two Main Concerns with Memory Getting
More informationios Development Lecture 1 Introduction to Objective-C Ing. Simone Cirani
ios Development Lecture 1 Introduction to ObjectiveC Ing. Simone Cirani email: simone.cirani@unipr.it http://www.tlc.unipr.it/cirani Simone Cirani, Ph.D. Corso IFTS Cisita ios Development 2014 Parma Università
More informationCOMP327 Mobile Computing Session: Lecture Set 1a - Swift Introduction and the Foundation Framework Part 2
COMP327 Mobile Computing Session: 2018-2019 Lecture Set 1a - Swift Introduction and the Foundation Framework Part 2 73 Other Swift Guard Already seen that for optionals it may be necessary to test that
More informationMobile Application Development
Object Lifecycle Mobile Application Development Creating objects Memory management Destroying objects Basic ios Development 11-Nov-11 Mobile App Development 1 11/11/11 2 Object Creation Two step process
More informationMemory management COSC346
Memory management COSC346 Life cycle of an object Create a reference pointer Allocate memory for the object Initialise internal data Do stuff Destroy the object Release memory 2 Constructors and destructors
More informationSDK Programming for Web Developers
1 SDK Programming for Web Developers Excerpted from iphone in Action Introduction to Web and SDK Development Christopher Allen and Shannon Appelcline MEAP Release: May 2008 Softbound print: December 2008
More informationITP 342 Mobile App Dev. Fundamentals
ITP 342 Mobile App Dev Fundamentals Object-oriented Programming Object-oriented programming (OOP) is a programming paradigm based on the concept of objects. Classes A class can have attributes & actions
More informationCS 47. Beginning iphone Application Development
CS 47 Beginning iphone Application Development Introductions Who, why, which? Shameless Plug: LoudTap Wifi Access (If it works..) SSID: Stanford Username/password: csp47guest Expectations This is a programming
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Memory Management and Garbage Collection CMSC 330 - Spring 2013 1 Memory Attributes! Memory to store data in programming languages has the following lifecycle
More informationReview (Basic Objective-C)
Classes Header.h (public) versus Implementation.m (private) @interface MyClass : MySuperclass... @end (only in header file) @interface MyClass()... @end (only in implementation file) @implementation...
More informationPage 1. GUI Programming. Lecture 13: iphone Basics. iphone. iphone
GUI Programming Lecture 13: iphone Basics Until now, we have only seen code for standard GUIs for standard WIMP interfaces. Today we ll look at some code for programming mobile devices. on the surface,
More informationGarbage Collection. CS 351: Systems Programming Michael Saelee
Garbage Collection CS 351: Systems Programming Michael Saelee = automatic deallocation i.e., malloc, but no free! system must track status of allocated blocks free (and potentially reuse)
More informationiphone Application Programming Lecture 3: Swift Part 2
Lecture 3: Swift Part 2 Nur Al-huda Hamdan RWTH Aachen University Winter Semester 2015/2016 http://hci.rwth-aachen.de/iphone Review Type aliasing is useful! Escaping keywords could be useful! If you want
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Memory Management and Garbage Collection CMSC 330 Spring 2017 1 Memory Attributes Memory to store data in programming languages has the following lifecycle
More informationItem 18: Implement the Standard Dispose Pattern
Item 18: Implement the Standard Dispose Pattern 1 Item 18: Implement the Standard Dispose Pattern We ve discussed the importance of disposing of objects that hold unmanaged resources. Now it s time to
More informationios Core Data Example Application
ios Core Data Example Application The Core Data framework provides an abstract, object oriented interface to database storage within ios applications. This does not require extensive knowledge of database
More informationThread Sanitizer and Static Analysis
Developer Tools #WWDC16 Thread Sanitizer and Static Analysis Help with finding bugs in your code Session 412 Anna Zaks Manager, Program Analysis Team Devin Coughlin Engineer, Program Analysis Team 2016
More informationVector and Free Store (Pointers and Memory Allocation)
DM560 Introduction to Programming in C++ Vector and Free Store (Pointers and Memory Allocation) Marco Chiarandini Department of Mathematics & Computer Science University of Southern Denmark [Based on slides
More informationITP 342 Advanced Mobile App Dev. Core Data
ITP 342 Advanced Mobile App Dev Core Data Persistent Data NSUser Defaults Typically used to save app preferences Property List (plist) in Documents Directory Data is in a dictionary or an array Coders
More informationMidterm 2. 7] Explain in your own words the concept of a handle class and how it s implemented in C++: What s wrong with this answer?
Midterm 2 7] Explain in your own words the concept of a handle class and how it s implemented in C++: What s wrong with this answer? A handle class is a pointer vith no visible type. What s wrong with
More informationAdvanced Object- C Features
Advanced Object- C Features Advanced Features Proper6es Categories Protocols Delegates Selectors Key- Value Coding Predicators Proper6es Provide access to object a?ributes Shortcut to implemen6ng ge?er/se?er
More informationPorting Objective-C to Swift. Richard Ekle
Porting Objective-C to Swift Richard Ekle rick@ekle.org Why do we need this? 1.2 million apps in the ios App Store http://www.statista.com/statistics/276623/numberof-apps-available-in-leading-app-stores/
More informationData Structures (list, dictionary, tuples, sets, strings)
Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in brackets: l = [1, 2, "a"] (access by index, is mutable sequence) Tuples are enclosed in parentheses: t = (1, 2, "a") (access
More informationHeap Management. Heap Allocation
Heap Management Heap Allocation A very flexible storage allocation mechanism is heap allocation. Any number of data objects can be allocated and freed in a memory pool, called a heap. Heap allocation is
More informationCompiler Construction D7011E
Compiler Construction D7011E Lecture 14: Memory Management Viktor Leijon Slides largely by Johan Nordlander with material generously provided by Mark P. Jones. 1 First: Run-time Systems 2 The Final Component:
More informationOverview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017
Overview of OOP Dr. Zhang COSC 1436 Summer, 2017 7/18/2017 Review Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in square brackets: l = [1, 2, "a"] (access by index, is mutable
More informationObjective-C. Deck.m. Deck.h. Let s look at another class. This one represents a deck of cards. #import <Foundation/Foundation.h> #import "Deck.
Deck.h #import @interface Deck : NSObject @interface Deck() @implementation Deck Deck.m Let s look at another class. This one represents a deck of cards. Deck.h #import
More informationTopics in Mobile Computing
Topics in Mobile Computing Workshop 1I - ios Fundamental Prepared by Y.H. KWOK What is ios? From Wikipedia (http://en.wikipedia.org/wiki/ios): ios is an operating system for iphone, ipad and Apple TV.
More informationITP 342 Mobile App Dev. Unit Testing
ITP 342 Mobile App Dev Unit Testing Testing Xcode provides you with capabilities for extensive software testing. Testing your projects enhances robustness, reduces bugs, and speeds the acceptance of your
More informationepicurious Anatomy of an ios app Robert Tolar Haining June 25, 2010 ConvergeSE
epicurious Anatomy of an ios app Robert Tolar Haining June 25, 2010 ConvergeSE + = Prototype iphone ipad Why iphone apps Simplicity Control Speed Revenue Epicurious Defined as a Recipe Utility Cookbook
More informationLecture 13: more class, C++ memory management
CIS 330: / / / / (_) / / / / _/_/ / / / / / \/ / /_/ / `/ \/ / / / _/_// / / / / /_ / /_/ / / / / /> < / /_/ / / / / /_/ / / / /_/ / / / / / \ /_/ /_/_/_/ _ \,_/_/ /_/\,_/ \ /_/ \ //_/ /_/ Lecture 13:
More information1 Dynamic Memory continued: Memory Leaks
CS104: Data Structures and Object-Oriented Design (Fall 2013) September 3, 2013: Dynamic Memory, continued; A Refresher on Recursion Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we continue
More informationDesigning iphone Applications
Designing iphone Applications 4 Two Flavors of Mail 5 Organizing Content 6 Organizing Content 6 Organizing Content 6 Organizing Content 6 Organizing Content Focus on your user s data 6 Organizing Content
More informationObjective-C and Cocoa User Guide and Reference Manual
Objective-C and Cocoa User Guide and Reference Manual Version 7.1 Copyright and Trademarks LispWorks Objective-C and Cocoa Interface User Guide and Reference Manual Version 7.1 March 2017 Copyright 2017
More informationRobust Memory Management Schemes
Robust Memory Management Schemes Prepared by : Fadi Sbahi & Ali Bsoul Supervised By: Dr. Lo ai Tawalbeh Jordan University of Science and Technology Robust Memory Management Schemes Introduction. Memory
More informationCS193E Lecture 7. Document-based Applications NSTableView Key-Value Coding
CS193E Lecture 7 Document-based Applications NSTableView Key-Value Coding Agenda Questions? Review: delegates, MVC Document-based apps Table views Key Value Coding Model, View, Controller Controller Model
More informationCOMP327 Mobile Computing Session: Tutorial Objective-C and the Foundation Framework
COMP327 Mobile Computing Session: 2010-2011 Tutorial 4-5 - Objective-C and the Foundation Framework 1 In these Tutorial Slides... These slides introduce you to Objective-C, with a focus on the object-oriented
More informationA little more Core Data
A little more Core Data A little more Core Data NSFetchedResultsController Interacts with the Core Data database on your behalf [fetchedresultscontroller objectatindexpath:] gets at row data [fetchedresultscontroller
More informationDeallocation Mechanisms. User-controlled Deallocation. Automatic Garbage Collection
Deallocation Mechanisms User-controlled Deallocation Allocating heap space is fairly easy. But how do we deallocate heap memory no longer in use? Sometimes we may never need to deallocate! If heaps objects
More informationMemory Allocation. Static Allocation. Dynamic Allocation. Dynamic Storage Allocation. CS 414: Operating Systems Spring 2008
Dynamic Storage Allocation CS 44: Operating Systems Spring 2 Memory Allocation Static Allocation (fixed in size) Sometimes we create data structures that are fixed and don t need to grow or shrink. Dynamic
More informationMobile Application Development
Mobile Application Development Lecture 12 Introduction to ObjectiveC 2013/2014 Parma Università degli Studi di Parma Lecture Summary ObjectiveC language basics Classes and objects Methods Instance variables
More information1 2 http://www.d.umn.edu/~gshute/softeng/object-oriented.html Polymorphism and overloading can lead to confusion if used excessively. However, the capability of using words or names to mean different things
More informationChapter 17 vector and Free Store. Bjarne Stroustrup
Chapter 17 vector and Free Store Bjarne Stroustrup www.stroustrup.com/programming Overview Vector revisited How are they implemented? Pointers and free store Allocation (new) Access Arrays and subscripting:
More informationCS61C : Machine Structures
inst.eecs.berkeley.edu/~cs61c/su06 CS61C : Machine Structures Lecture #6: Memory Management CS 61C L06 Memory Management (1) 2006-07-05 Andy Carle Memory Management (1/2) Variable declaration allocates
More informationCocoa. Last Week... Music 3SI: Introduction to Audio/Multimedia App. Programming. Today... Why Cocoa? Wikipedia - Cocoa
Music 3SI: Introduction to Audio/Multimedia App. Programming IDE (briefly) VST Plug-in Assignment 1 hints Last Week... Week #5-5/5/2006 CCRMA, Department of Music Stanford University 1 2 Today... Cocoa
More informationCMSC 330: Organization of Programming Languages. Memory Management and Garbage Collection
CMSC 330: Organization of Programming Languages Memory Management and Garbage Collection CMSC330 Fall 2018 1 Memory Attributes Memory to store data in programming languages has the following lifecycle
More informationCS 103 Lab The Files are *In* the Computer
CS 103 Lab The Files are *In* the Computer 1 Introduction In this lab you will modify a word scramble game so that instead of using a hardcoded word list, it selects a word from a file. You will learn
More informationWhat the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control.
C Flow Control David Chisnall February 1, 2011 Outline What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope Disclaimer! These slides contain a lot of
More informationCS 241 Honors Memory
CS 241 Honors Memory Ben Kurtovic Atul Sandur Bhuvan Venkatesh Brian Zhou Kevin Hong University of Illinois Urbana Champaign February 20, 2018 CS 241 Course Staff (UIUC) Memory February 20, 2018 1 / 35
More informationComputer Science, a Mac, and You. Kevin Cathey Junior, Computer Science
Computer Science, a Mac, and You Kevin Cathey Junior, Computer Science Roadmap Introduction to Apple s Developer Tools Xcode & Instruments Implement three MP s acm.uiuc.edu Introduction to Developer Tools
More informationITP 342 Mobile App Development. Data Persistence
ITP 342 Mobile App Development Data Persistence Persistent Storage Want our app to save its data to persistent storage Any form of nonvolatile storage that survives a restart of the device Want a user
More informationAssignment I Walkthrough
Assignment I Walkthrough Objective Reproduce the demonstration (building a calculator) given in class. Materials By this point, you should have been sent an invitation to your sunet e-mail to join the
More informationPraktikum Entwicklung von Mediensystemen mit
Praktikum Entwicklung von Mediensystemen mit Sommersemester 2013 Fabius Steinberger, Dr. Alexander De Luca Today Organization Introduction to ios programming Hello World Assignment 1 2 Organization 6 ECTS
More informationITP 342 Mobile App Development. Data Persistence
ITP 342 Mobile App Development Data Persistence Persistent Storage Want our app to save its data to persistent storage Any form of nonvolatile storage that survives a restart of the device Want a user
More informationMy First Cocoa Program
My First Cocoa Program 1. Tutorial Overview In this tutorial, you re going to create a very simple Cocoa application for the Mac. Unlike a line-command program, a Cocoa program uses a graphical window
More informationWhen we re first learning Cocoa (or Java, or Qt, or any other application framework),
MacDevCenter http://www.macdevcenter.com/lpt/a/4752 6 April 2004 The Cocoa Controller Layer by Michael Beam When we re first learning Cocoa (or Java, or Qt, or any other application framework), one of
More informationWorking Effectively with Objective-C on iphone OS. Blaine Garst Wizard of Runtimes
Working Effectively with Objective-C on iphone OS Blaine Garst Wizard of Runtimes 2 Working Effectively with Objective-C on ios 4 Blaine Garst Wizard of Runtimes 3 Objective-C is the language of Cocoa
More informationITP 342 Mobile App Dev. Interface Builder in Xcode
ITP 342 Mobile App Dev Interface Builder in Xcode New Project From the Main Menu, select the File à New à Project option For the template, make sure Application is selected under ios on the left-hand side
More information