[iPhone SDK] Nib vs. JIT allocation: memory pressure and programmer time

I'm going to ask a question that there's no single answer to. Instead, I'm more interested to know how different people approach the same problem.
Lately I've been finding I'm of two minds when I have a UI element or view controller that isn't always used. On the one hand, the iPhone is a fairly memory-constrained environment, and the rules for developing for it are pretty explicit: don't use memory until you need it. That suggests "just in time" or "lazy" allocation: don't allocate it until you actually need it for the first time. After that, hold onto it in case you need it again, but be ready to free it if you receive a memory warning. My code is full of methods with names like "ensureViewerLoaded" which I call just before I need the object in question to allocate it if necessary.
(For context: my applications are generally UIKit-based utility or data-browsing/editing apps with little graphical or computational complexity and very little memory pressure overall. So far, I've only released one app; at its greediest, it consumes about 1 MB. This isn't because I'm a brilliant programmer--although I do try to be parsimonious--it's just because the app doesn't need much memory to do what it's supposed to do.)
But on the other hand, allocating those same objects in nib files (or, in other cases, loading them from plists or object archives) makes me more nimble. I've found that it reduces the weight of my code, paring it down to the logic I really need to be paying attention to. That lets me code faster--which means I can modify faster and release faster. And one thing I'm finding is that on the App Store, more releases means more sales. And more sales means I get to buy a MacBook Air with an SSD sooner, and thus save my back a few pounds of strain and my patience a few seconds of compilation. ;^)
I guess what I'm asking is, how are you resolving these sorts of trade-offs? Where are you trading phone resources for programmer resources, and where are you deciding not to? And how is the type of app you're writing influencing that decision?

My applications don't need much memory either, so I let everything happen in the nib file. I typically have about three views to worry about, and nothing significantly graphical in any of them.

Similar Messages

  • Problem description: My iMac (early 2008) with OS 10.10.2 runs slow.  I have run EtreCheck several times, and I am unable to move beyond Problem System Launch Agents (11 processes killed due to memory pressure) and Launch Daemons (12 processes killed

    Problem description:
    My iMac (early 2008) with OS 10.10.2 runs slow.  I have run EtreCheck several times, and I am unable to move beyond Problem System Launch Agents (11 processes killed due to memory pressure) and Launch Daemons (12 processes killed).
    EtreCheck version: 2.1.8 (121)
    Report generated April 14, 2015 at 9:50:48 AM EDT
    Download EtreCheck from http://etresoft.com/etrecheck
    Click the [Click for support] links for help with non-Apple products.
    Click the [Click for details] links for more information about that line.
    Hardware Information: ℹ️
        iMac (24-inch, Early 2008) (Verified)
        iMac - model: iMac8,1
        1 3.06 GHz Intel Core 2 Duo CPU: 2-core
        4 GB RAM Upgradeable
            BANK 0/DIMM0
                2 GB DDR2 SDRAM 800 MHz ok
            BANK 1/DIMM1
                2 GB DDR2 SDRAM 800 MHz ok
        Bluetooth: Old - Handoff/Airdrop2 not supported
        Wireless:  en1: 802.11 a/b/g/n
    Video Information: ℹ️
        NVIDIA GeForce 8800 GS - VRAM: 512 MB
            iMac 1920 x 1200
    System Software: ℹ️
        OS X 10.10.2 (14C1510) - Time since boot: 4 days 20:29:22
    Disk Information: ℹ️
        Hitachi HDS721010KLA330 disk0 : (1 TB)
            EFI (disk0s1) <not mounted> : 210 MB
            Mac iBook HD (disk0s2) / : 999.35 GB (521.60 GB free)
            Recovery HD (disk0s3) <not mounted>  [Recovery]: 650 MB
    USB Information: ℹ️
        Apple Inc. Built-in iSight
        Apple, Inc. Keyboard Hub
            Apple, Inc Apple Keyboard
        Apple Computer, Inc. IR Receiver
        Apple Inc. BRCM2046 Hub
            Apple Inc. Bluetooth USB Host Controller
    Configuration files: ℹ️
        /etc/sysctl.conf - Exists
    Gatekeeper: ℹ️
        Mac App Store and identified developers
    Problem System Launch Agents: ℹ️
        [killed]    com.apple.CallHistoryPluginHelper.plist
        [killed]    com.apple.CallHistorySyncHelper.plist
        [killed]    com.apple.coreservices.appleid.authentication.plist
        [killed]    com.apple.icloud.fmfd.plist
        [killed]    com.apple.Maps.pushdaemon.plist
        [killed]    com.apple.printtool.agent.plist
        [killed]    com.apple.SafariNotificationAgent.plist
        [killed]    com.apple.sbd.plist
        [killed]    com.apple.scopedbookmarkagent.xpc.plist
        [killed]    com.apple.telephonyutilities.callservicesd.plist
        [killed]    com.apple.warmd_agent.plist
        11 processes killed due to memory pressure
    Problem System Launch Daemons: ℹ️
        [killed]    com.apple.AssetCacheLocatorService.plist
        [killed]    com.apple.ctkd.plist
        [killed]    com.apple.emond.aslmanager.plist
        [killed]    com.apple.icloud.findmydeviced.plist
        [killed]    com.apple.ifdreader.plist
        [killed]    com.apple.nehelper.plist
        [killed]    com.apple.nesessionmanager.plist
        [killed]    com.apple.periodic-daily.plist
        [killed]    com.apple.periodic-weekly.plist
        [killed]    com.apple.softwareupdate_download_service.plist
        [killed]    com.apple.wdhelper.plist
        [killed]    org.cups.cupsd.plist
        12 processes killed due to memory pressure
    Launch Agents: ℹ️
        [not loaded]    com.adobe.AAM.Updater-1.0.plist [Click for support]
        [running]    com.adobe.AdobeCreativeCloud.plist [Click for support]
    Launch Daemons: ℹ️
        [loaded]    com.adobe.fpsaud.plist [Click for support]
        [loaded]    com.adobe.SwitchBoard.plist [Click for support]
        [running]    com.arubanetworks.via.NetworkMonitorLaunchd.plist [Click for support]
        [loaded]    com.microsoft.office.licensing.helper.plist [Click for support]
    User Launch Agents: ℹ️
        [loaded]    com.adobe.AAM.Updater-1.0.plist [Click for support]
        [loaded]    com.adobe.ARM.[...].plist [Click for support]
        [loaded]    com.adobe.ARM.[...].plist [Click for support]
        [loaded]    com.google.keystone.agent.plist [Click for support]
        [running]    com.spotify.webhelper.plist [Click for support]
    User Login Items: ℹ️
        ChronoSyncBackgrounder    Application  (/Library/Application Support/ChronoSync/ChronoSyncBackgrounder.app)
        Dropbox    Application  (/Applications/Dropbox.app)
        Canon IJ Network Scanner Selector2    Application Hidden (/Library/Printers/Canon/IJScanner/Utilities/Canon IJ Network Scanner Selector2.app)
        Google Drive    Application  (/Applications/Google Drive.app)
    Internet Plug-ins: ℹ️
        Google Earth Web Plug-in: Version: 6.1 [Click for support]
        Default Browser: Version: 600 - SDK 10.10
        AdobeExManDetect: Version: AdobeExManDetect 1.1.0.0 - SDK 10.7 [Click for support]
        Flip4Mac WMV Plugin: Version: 3.1.0.24   - SDK 10.8 [Click for support]
        OVSHelper: Version: 1.1 [Click for support]
        AdobeAAMDetect: Version: AdobeAAMDetect 2.0.0.0 - SDK 10.7 [Click for support]
        AdobePDFViewerNPAPI: Version: 11.0.10 - SDK 10.6 [Click for support]
        DivX Web Player: Version: 3.2.4.1250 - SDK 10.6 [Click for support]
        FlashPlayer-10.6: Version: 17.0.0.134 - SDK 10.6 [Click for support]
        Flash Player: Version: 17.0.0.134 - SDK 10.6 Outdated! Update
        iPhotoPhotocast: Version: 7.0
        QuickTime Plugin: Version: 7.7.3
        SharePointBrowserPlugin: Version: 14.4.8 - SDK 10.6 [Click for support]
        AdobePDFViewer: Version: 11.0.10 - SDK 10.6 [Click for support]
        Silverlight: Version: 5.1.20913.0 - SDK 10.6 [Click for support]
        JavaAppletPlugin: Version: 15.0.0 - SDK 10.10 Check version
    User internet Plug-ins: ℹ️
        WebEx: Version: 1.0 [Click for support]
        Google Earth Web Plug-in: Version: 7.1 [Click for support]
    3rd Party Preference Panes: ℹ️
        Adobe Version Cue CS2  [Click for support]
        Flash Player  [Click for support]
        Flip4Mac WMV  [Click for support]
        VIA PrefPane  [Click for support]
    Time Machine: ℹ️
        Time Machine not configured!
    Top Processes by CPU: ℹ️
             3%    WindowServer
             3%    Mail
             2%    com.apple.iCloudHelper
             1%    Creative Cloud
             1%    Google Chrome
    Top Processes by Memory: ℹ️
        223 MB    Google Chrome
        150 MB    Finder
        129 MB    Google Chrome Helper
        112 MB    Mail
        69 MB    Google Drive
    Virtual Memory Information: ℹ️
        35 MB    Free RAM
        1.45 GB    Active RAM
        1.45 GB    Inactive RAM
        888 MB    Wired RAM
        27.01 GB    Page-ins
        851 MB    Page-outs

    When you see a beachball cursor or the slowness is especially bad, note the exact time: hour, minute, second.  
    These instructions must be carried out as an administrator. If you have only one user account, you are the administrator.
    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad and start typing the name.
    The title of the Console window should be All Messages. If it isn't, select
              SYSTEM LOG QUERIES ▹ All Messages
    from the log list on the left. If you don't see that list, select
              View ▹ Show Log List
    from the menu bar at the top of the screen.
    Each message in the log begins with the date and time when it was entered. Scroll back to the time you noted above.
    Select the messages entered from then until the end of the episode, or until they start to repeat, whichever comes first.
    Copy the messages to the Clipboard by pressing the key combination command-C. Paste into a reply to this message by pressing command-V.
    The log contains a vast amount of information, almost all of it useless for solving any particular problem. When posting a log extract, be selective. A few dozen lines are almost always more than enough.
    Please don't indiscriminately dump thousands of lines from the log into this discussion.
    Please don't post screenshots of log messages—post the text.
    Some private information, such as your name, may appear in the log. Anonymize before posting.

  • HT201210 my iphone 1st gen is stuck in recovery mode and every time i try to reinstall firmware i get an error code 1015 can anyone help please?

    my iphone 1st gen is stuck in recovery mode and every time i try to reinstall firmware i get an error code 1015 can anyone help please?

    Make sure you are using current iTunes on your computer. Click the iTunes Tab at the top of this page. Or try to Restore your iPhone with a different computer.

  • TS1631 When I ring someone from my iPhone 4 they can't hear me sometimes and other times they can hear me fine. This has only started happening since I updated to iOS 6 it was perfect the day before.

    When I ring someone from my iPhone 4 they can't hear me sometimes and other times they can hear me fine. This has only started happening since I updated to iOS 6 it was perfect the day before.

    Good news! I believe I have fixed my phone!!
    A friend of mine was having the same problem that I was having where you could hear other people but they couldn't hear you.
    We fixed the problem by redownloading the 4.2.1 update. 4th post down on this page: http://forums.macrumors.com/showthread.php?t=1052794&page=5 is a list of links to the update files. I downloaded the one for my phone and did a restore (from a backup) after downloading the file and double clicking it so iTunes opens. Since I've done this my phone has been working perfectly again!
    It might take you a few tries, it took my friend 3 tries until his worked right and it worked for me on the first try. I'm guessing something was screwing up during the download.

  • Hello, I have the new iPhone 5. When sending iMessages to other iPhones sometimes it will send as an iMessage and other times iMessage does not work so I have to send it as a text message. Can anyone help me?

    Does it matter if i am on WiFi or 3G?

    There is an earlier thread that was answered by an Apple employee that states they are seeing the iMessage and Facetime servers are down. It is unknown when they will return, however it generally is not an extended period of time.

  • Unable to download Xcode 3.2.2 with iphone SDK (Intego firewall problem?)

    Hello. I logged into Apple's development site, to download Xcode 3.2.2 w/iphone SDK. I clicked on the link and started the download, but I think my firewall is blocking it.
    Which is odd, ContentBarrier is set to DISABLED for my account. I should have full access.
    Are there specific override settings I need to add to a 'trusted sites' entry, despite already having configured my Mac full admin access?
    Thanks!

    HI,
    From the Safari Menu Bar click Safari/Preferences then select the General tab. Where you see: Open "safe" files after downloading, make sure that box is selected.
    Carolyn

  • IPhone SDK - Download manager sample

    I need a download manager in my app. I want to have it download a bunch of files in a different thread so that user can keep working. Once the downloads are done the caller gets notified. Since the app cannot run in the background, the download should be restartable.
    Does anyone know if there is already something out there?
    Thanks in advance.
    -TRS

    Another victim here. Happily started downloading iphone SDK just after purchasing my new MacBook and it always stops at 2.1 GB. And of course it is corrupted.
    For those who are thinking about OS or firewalls, here are my trials:
    1. From my MacBook at home
    2. From my HP laptop at home
    3. From my desktop at home
    4. From my HP laptop at work
    5. From my Ubuntu at home
    6. From my Ubuntu virtual machine at work.
    Do you think it is still a client problem? Or the version on the server is corrupted?

  • IPhone SDK Download Problems

    I have just made the account and started the long download process for the iPhone SDK. When I download the file and it completes the process, I click on it and it says Disk Image not able to mount. I tried that three more times and it still won't open. Any suggestions?

    Another victim here. Happily started downloading iphone SDK just after purchasing my new MacBook and it always stops at 2.1 GB. And of course it is corrupted.
    For those who are thinking about OS or firewalls, here are my trials:
    1. From my MacBook at home
    2. From my HP laptop at home
    3. From my desktop at home
    4. From my HP laptop at work
    5. From my Ubuntu at home
    6. From my Ubuntu virtual machine at work.
    Do you think it is still a client problem? Or the version on the server is corrupted?

  • Session Expired - iPhone SDk download

    hi,
    I am trying to download iPhone SDK but always get the Session Expired error.
    Even when I am logged in.
    How can I download the SDK?
    Regards
    Sajid

    Another victim here. Happily started downloading iphone SDK just after purchasing my new MacBook and it always stops at 2.1 GB. And of course it is corrupted.
    For those who are thinking about OS or firewalls, here are my trials:
    1. From my MacBook at home
    2. From my HP laptop at home
    3. From my desktop at home
    4. From my HP laptop at work
    5. From my Ubuntu at home
    6. From my Ubuntu virtual machine at work.
    Do you think it is still a client problem? Or the version on the server is corrupted?

  • IPhone SDK to iPhone...?

    Hi,
    I know this long post may seem very disturbing to some members, but it is important for me to post it.
    Today (July 12th), I have struggled, and struggled, and struggled to try and use the iPhone SDK on a PPC based mac. And yes, I did succeed! I had to modify Xcode & iPhone simulator in several ways to make it build & run properly. I have started to learn how to use Interface builder for iPhone.
    However, I was not aware that the $99 dollar fee was to get your app onto the iPhone, I though the fee was for getting your app on to the app store. I was so disappointed that after about 4 hours of fiddling around Finder & hidden files to modify Xcode, I wouldn't be able to try my application on my father's iPod Touch.
    So then, I tried different methods:
    1. I did it the traditional way; plugging in the iTouch and using "organizer" in Xcode to sync. It gave me the well known error message that verification had failed.
    2. I set the SDK to "device iPhone 2.0", so that Xcode would build my test app as an "iPhoneos-release" app. Then, I dragged the resulting application into iTunes/Applications (via iTunes itself). Worked fine. Pressed sync, and it gave me the famous warning that the app failed verification. I wasn't very pleased.
    So now here I am. I do not want to sell or place anything on the App Store. All I would like is to develop applications for my father's iTouch. I have been developing AppleScript Studio apps for about 3 years now, a new platform is interesting. I am aware that some organisation created a Mac OS X application named "Pwnage" and that would let me install my app on the iPod Touch. However, it's a hack, and I really do NOT want to hack the device.
    My end question would be, is there any way to "bypass" the $99 fee? I only want the app for my family's personal use.
    Regards,
    Philippe H.

    But don't you need a server for ad-hoc stuff?
    http://www.tuaw.com/2008/06/11/what-does-ad-hoc-app-distribution-mean-for-users/
    Also, the mini-app would really be for personal use, so I don't think the app store is right for that.

  • My iPhone 4S frequently shutdown (atleast once per week) and I have to restart again by pressing power button

    My iphone 4s frequently shutdown (atleast once a week) and every time I need to restart again. Please advice if any solution or I need to replace the unit which I bought, 2 months back, purchase online from apple stores.

    Hello Ingo2711,
    Many thanks for providing necessary procedure to re-setup my phone. I able to complete all the recommended steps sucessfully and restore my data from the backup. Await to see the result and will update to you.
    Kind Regards
    Abdul

  • IPhone SDK 2.2 memory corruption

    Hello. I'm working on an application for iPhone SDK 2.2 and seem to be having weird memory corruption problems. Not necessarily leaks because using Instruments shows my memory stamp never going above about 1.8 megs. The nature of the app is a database of animals so I'm constantly loading and unloading sounds and images. None of the objects are very large (at most I'll have 4 800k pngs loaded at once) and I've checked and rechecked my alloc/retain/release and everything is in order (hence no memory usage increase). However...after using the application for a while I'll notice strange behavior. For example:
    1) we have a UILabel as the title for each page. After a while the font size of this will change.
    2) I have several screens with a subclassed UIScrollView where images are loaded and then added to. The problem shows itself here by the images not showing up. there's no crash, stepping through the debugger shows that the image loads up fine, it's just that the image is not there.
    3) I have a UILabel at the top of an animal description screen, which in the nib file is called "Animal Name" by default. This will change to show "Animal Name" at the top.
    I've removed all audio in our latest build so that isn't the problem. What I'm starting to suspect is that altering anything defined in a nib file will cause corruption. For example, the UIScrollView is defined in the nib file, and I constantly am reassigning the contents of that with a UIImageView. This UIImageView is handled within the subview class like :
    UIImageView *imgView = [[UIImageView alloc] initWithImage: [ UIImage imageWithContentsOfFile:[[NSBundle mainBundle ] pathForResource:imageToLoad ofType:@"png" ]] ];
    imgView.tag = 50;
    [self addSubview:imgView ];
    [ imgView release ];
    Then later when moving away from the screen I'll find that view's tag and remove it from the superview (since addSubView increases the retain count, the alloc+addSubView is cancelled by release+removeFromSuperView)
    I can't explain why titles that are never changed would be affected, but it must somehow be related. What I'm wondering is: are there any known issues involving modification of the contents of objects defined in Nib files? Perhaps the memory allocated when initWithNibName is restrained, then any modification of objects allocated within it can cause corruption. I'm starting to think I should just alloc and free anything modified in code and skip using nib files altogether (I reset the text on buttons for example). If this is a known issue please let me know. I'll give you more information if I can.
    Thank you

    Just download the huge SDK package and install. No need to uninstall the old SDK.

  • Release memory in iPhone SDK

    Hi,
    1. I want to release previous memory before I redraw the screen. Is this the right way to do it using iPhone SDK?
    [self.securityCodeView release];
    self.securityCodeView = [[SecurityCodeView alloc] initWithFrame:Frame];
    [self addSubview:securityCodeView];
    [\b]
    2. How do I refresh the screen without having to ALLOC memeory again? For example, I draw the screen ([self addSubview:securityCodeView]) and after one second, the screen needs to be redrawn (what statement to use?).
    3. How do you retain some UIViews without redrawing since they don't need to be redrawn again (what statement to use)? For example, backgroundView needs not to be redrawn.
    Thank you.

    I would suggest you read the docs on Memory Management on Obj-C. Basically anything you allocate explicitly will remain allocated (with a ref count of 1) until you explicitly do a release:
    [myView release];
    When you add a view to another view's subview, that view's ref count is incremented. So you can safely release the added view and yet use the references to the object throughout the code (as long as the parent view is not released/deallocated).

  • IPhone SDK: unrecognized selector

    I'm relatively new to Objective-C/iPhone SDK development. I have an issue that really seems to produce random (or at least nondeterministic) errors, all of which are "unrecognized selector" errors.
    I have a UITableViewController that is populated with table names from a MySQL database. When I select a table name, a second UITableViewController is created to display detailed data. I thought this was working just fine, but I discovered I have problems when I select a certain table name, (detailed results are displayed in second UITableViewController), go back, select the same table name, (...), go back, and select the same table name a third time. The Simulator explodes and gives me an error like:
    * -[UICGColor length]: unrecognized selector sent to instance 0x1050810
    Sometimes it's related to UICGColor, sometimes it's related to CALayerArray. Sometimes it doesn't produce any error at all and just terminates.
    What's also weird is that only some of the table names cause this to happen. Also, if I cycle through several table names (i.e., not select the same table over and over), the app is fine. I would tend to think that maybe something is wrong with my database or MySQL C API usage, but the fact that things are perfectly fine the first and second (and third and fourth and ... and nth for some tables) time baffles me. I'm not using any dynamic method calling either -- just straight
    [ object method: ] syntax, so I'm not sure how it suddenly can "lose" the selector reference that it was perfectly happy to use earlier. As far as I can tell, I'm releasing memory as necessary.
    Any clues why this seems to be so weird and unpredictable? I can provide source if it would help.

    Ugh. Problem solved. I was tampering with autorelease, and it got me into trouble. I had this:
    query = [ [ [ NSString alloc ] initWithFormat:@"...%@", [ [ tableView cellForRowAtIndexPath:indexPath ] text ] ] autorelease ];
    I thought that I should autorelease the "anonymous" object I created. It made sense at the time, but upon thinking about retain/release more closely, it's so clear now.

  • Learning iPhone SDK - Trying to draw an image

    Although I have programmed for Mac in the last years, I have never used Mac-specific technologies as Cocoa (I have programmed more in OpenGL, SDL, and the like).
    Now I am getting started with the iPhone SDK. I'd like to do some OpenGL|ES stuff, but since it is not supported in the Simulator, and you need to join the Developer Program to test stuff on directly on the device (and admission of new members is closed right now), I am focused on other stuff right now, like using Core Graphics for drawing images on the iPhone.
    My application is based on the Cocoa Touch Application template. I left the default code except for a few changes.
    In file "UntitledAppDelegate.m", I have changed the method applicationDidFinishLaunching to:
    - (void)applicationDidFinishLaunching:(UIApplication *)application {
    window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    contentView = [[[MyView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
    [window addSubview:contentView];
    [window makeKeyAndVisible];
    Then, in the MyView interface file (MyView.h), I have added the attribute "UIImageView* image;" to the class, which is declared as a property, and synthesized.
    In the class implementation (MyView.m), I have changed the method initWithFrame to:
    - (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
    self.backgroundColor = [UIColor darkGrayColor];
    image = [self loadImageView:@"box01.png"];
    [self addSubview:image];
    return self;
    loadImageView is a private method I have implemented as:
    - (UIImageView *)loadImageView:(NSString *) imageName {
    UIImage *img = [UIImage imageNamed:imageName];
    UIImageView *theView = [[UIImageView alloc] initWithImage:img];
    return theView;
    Since I have loaded the UIImage, and initialized a UIImageView with it, and the image view is added as a subview of the main view attached to the window, I thought it should be everything needed to draw an image on the screen. But nothing is visible. The screen is simply black when I run this on the Simulator. It doesn't even set the background to dark gray.
    So I need some help with this, I sure that anyone with experience in Mac programming will know how to help me.
    Thank you in advance.
    Message was edited by: Jedive

    I removed the XIB file from the project, but that didn't help. It was a problem with my inexperience with Objective-C. When accessing class properties in a method of the same class, i was not putting "self." before the property (in C++ that's redundant). For example, in the line "window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];". After adding it, it works correctly.

Maybe you are looking for