Sunday, 15 February 2015

objective c - ARC & Memory managment in my app -


edit

I found out that my screen is not zero because They keep RefCt but my question is why is not RefCt 0? I just create, add and remove the scene. In addition, a scrollpamp has also been added to the devices:

scandend of instruments

then you see in the beginning

Malloc 1 maintains initwithframe,: 2 initwithframe, release: 1 - [UIView (internal) _addSubview: Posted: Relative:], maintains: 2 Quartzcor Maintain Calier Layout Stallers: 3 Quartzcos

  - [UIView (internal) _addSubview: In case:  

relative:], maintain : 2

line? I think that is the reason why I still think there is a RefCt.

END

I'm trying to clean my code and finally speed up my app but I do not think I have a whole memory management thing Actually there is a view for the user in my app, but it can switch to different views in the menu. Now I think the most argument is that at the same time only one scene should be allocated and memory should be taken and when a user selects another view then the current view should be released and allocated to the selected view. should be done. I tried to create a new view when I tried to do something like that:

  - (zero) remove menu {@autoreleasepool {for (see UIView * container. See subviews) {NSLog (@ " See to remove:% @ ", see); [ViewFromSuperview]; }}}   

Say that the user chose to show the screen again. This bit of code will run:

  - (zero) createStartScreen {if (startScreen == zero) {startScreen = [[StartScreen allocated] initWithFrame: CGRectMake (0, 0, [UIScreen main screen] .bounds.size.width, [UIScreen main screen] .bounds.size.height)]; Start.screen.delegate = self; Start.screen.layer.shadowColor = [[UIColor blackColor] CGColor]; Start.screen.layer.shadowOffset = CGSizeMake (0.0f, 0.0f); Start.screen.layer.shadowRadius = 5.0f; Start.screen.layer.shadowOpacity = 1.0f; }}   

I installed a breakpoint there and found out that the beginning was not zero, while I thought it should be because I removed it from the supervision (the pointers of that var Had tried too) If I understand that this starts well, then the countdown to zero is not correct. Apart from this, I am using ARC, so I thought that ARC will handle this well.

What is the correct way to keep the user from seeing the memory no longer visible?

It depends on what ivar start.screen is if your code In the controller, startScreen is defined as a strong Iver, then after the allocation, there will be a rebound of 1, and after one of the 2 returns, you can see it as a subview form in its visual hierarchy Will set in After this, removing the view from your supervision will reduce the refinquity for only 1 and you have to explicitly zero the variable to delock it.

Another option is that your view is linked to your view controller via the storyboard or XIB file and an outlet. In that case, your visual ivar should be set as a weak variable since it has already been strengthened by someone else.

Read about differences between the strong and weak qualifiers.

The last thing - for better readability, this is a general conference that you want to install lazy, then you can define the code that you write, which code you want to enter in the override holder method < Code> createStartScreen .

No comments:

Post a Comment