0

I am almost finished with my first app (long way but fun times)

I am trying for a week to decrease my memory usage of the app but if that does not work i want to make sure it dealloc's a view after its been used but i see that that doesnt happen...

I dont have a memory issue with the searchviewController its more the DetailsViewController that uses 100 mb ram.

I will try to show how my app is build up in a summary:

Searchview controller 

The main screen --> UIViewController with tableview 

in the didSelectRowAtIndex i have:

    DetailsViewController *controller = [[DetailViewsController alloc]initWithNibName:@"DetailsViewController" bundle:nil];

    SearchResult *searchResult = [searchResults objectAtIndex:indexPath.row];
    controller.searchResult = searchResult;


DetailsViewController

The details screen, is called when select a row, its a UIview that has a subview (a custom scrollview) the custom scrollview has the icarousel (custom uiview)

.h

@property (nonatomic,weak) SearchResult *searchResult;

.m

@property (nonatomic, retain) iCarousel *carousel;
@property (nonatomic, retain) UINavigationItem *navItem;

Implementation:

    MGBox *tablesGrid, *table1;

ViewDidLoad:

//Add barButton
UIBarButtonItem *reactButton = [[UIBarButtonItem alloc]..];
carousel = [[iCarousel alloc] init..];

//Add Tablesgrid
tablesGrid = [MGBox boxWithSize:tablesGridSize];
tablesGrid.contentLayoutMode = MGLayoutGridStyle;
[self.scrollview.boxes addObject:tablesGrid];

//Add Table
table1 = MGBox.box;
[tablesGrid.boxes addObject:table1];

after this i have functions that add the searchResult to a label and fill the icarousel (that has max 6 items), icarousel is a uiview that i added as a subview to scrollview etc..

When i push back on the navigationBar and go back to the main view controller it doesn't dealloc the view, why ? (nslogged the dealloc but is never called). After memory warning it calls the ViewDidUnload and makes some memory free but still no dealloc....

I have no reference to other objects right ? except for the searchResult but i set it on weak so it should not be a reference right ?

Some info:

After a search on the mainview i have :

Live bytes: 5,75 mb Living: 27.342 Transistory: 68.200 Overall bytes: 25.30 mb

After selecting a row and going into the detailsViewController i have:

Live bytes: 5.4 mb Living: 32.498 Transistory: 76.488 Overall bytes: 29.55 MB

After dragging the subview row of icarousel (watching the pictures):

Live bytes: 5.5 mb Living: 32.798 Transistory: 122.850 Overall bytes: 36.41 MB

After selecting some tables in the custom table view

Live bytes: 5.7 mb Living: 33.508 Transistory: 161.80 Overall bytes: 40.12 MB

after opening a link in app and going back (opens in modal view and dismiss it again)

Live bytes: 6.7 mb Living: 43.821 Transistory: 371.761 Overall bytes: 144.95 MB

After clicking on the pictures and make the photos in fullscreen and coming back in detailscreenview again (opens modal and dismiss)

Live bytes: 6.76 mb Living: 43.798 Transistory: 400.850 Overall bytes: 155.69 MB

And if i go back to another row it never gets less it just adds

Dont be to hard on me or just shut the topic down for no reason..

Give me some tips or advice or if you dont know what the "problem" is just explain me what these are: Live Bytes - #living - #Transitory - Overall Bytes - # Overall

And i would like to thank this website for all the information that it has because without it i would never got so far

MichaelAngelo
  • 375
  • 2
  • 19

1 Answers1

2

In answer to your question:

  1. You said "when I push back" on the navigation bar. I hope you meant that you "popped" back. You push to go to a secondary controller/scene. You pop to go back. See popViewControllerAnimated. Likewise, every time you presentViewController, you should have an associated dismissViewControllerAnimated.

  2. If using storyboards, make sure you don't have circular segues in your storyboard (e.g. segue from A to B and another from B to A). See memory not releasing with ARC and storyboard in iOS 5.1 for a brief discussion on this topic.

  3. The other possibility is a "strong reference cycle" (a.k.a. "retain cycle"). See the Advanced Memory Management Programming Guide. Anything that could be maintaining a strong reference to your controllers could cause this problem. Less obvious examples include things like repeating NSTimer objects.


Update:

Some general counsel regarding memory management

  • If you're having memory issues, you should always run your code through the static analyzer. This is especially important if you don't use ARC, or if you use any Core Foundation calls, but it's generally a good first step when encountering any memory issues.

  • See Finding leaks with Instruments for guidance on how to use Instruments to find leaks in your app.

  • Sometimes, when you have a spike in memory allocations, it's useful to determine what's causing the spike. For specific advice how to go from you allocations, to a more meaningful analysis of the source of those allocations, see point #4 of this Stack Overflow answer. In short, highlight one of your unexplained jumps in allocations, set the bottom window to show you the call tree, hide system libraries, and see in which of your routines the memory is being consumed.

Community
  • 1
  • 1
Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • i didnt use storyboard...is it a good idea to refactor everything to storyboard ? – MichaelAngelo Jan 10 '13 at 15:41
  • @user1876006 No, not necessary. But the same principle applies with NIBs. If you push from A to B, you just need to make sure you never push from B to A, but rather that you pop from B back to A. This is the logical equivalent to making sure that one's storyboard doesn't have circular references. I've tried to clarify my answer. – Rob Jan 10 '13 at 15:43
  • the navigationbar that i added in the appDelegate "makes" the back button, i assume thats popping the view or not ? – MichaelAngelo Jan 10 '13 at 15:56
  • @user1876006 Yes, if you're just tapping on the system generated "back" button, then you're popping fine. If you added your own manual button that does `pushViewController` or `presentViewController`, then that's problematic. FYI, I've added some additional general counsel for (a) analyzing code; (b) finding leaks; and (c) identifying allocations (if, for some reason, you were unsure as to what they were being caused by). – Rob Jan 10 '13 at 15:57
  • i will read the things you posted and try to find the answer why it doesnt dealloc ! tnx m8! – MichaelAngelo Jan 11 '13 at 00:06