iPhone – How does IOS decide which objects DidRecEMemoryWarning message?

I am developing an iPhone application in which many UIViews are dynamically added to and removed from the main UIWindow.

Simulation in the simulator When a low memory error occurs, I found that not all view controllers receive the didReceiveMemoryWarning notification. Unfortunately, these are the controllers that are most conducive to implementing this method.

I can’t seem to find out where the method is called And good information on the way. I have read mentioning that it is sent to “all UIViewControllers”, but it is not. Adding a breakpoint in one of the classes that receives notifications is not particularly instructive.

This is a complicated project, but there are ways to add these views:

- (void) showMyView
{
if(!myViewController){
myViewController = [[MyViewController alloc]init];
[window addSubview:myViewController.view];
}
}

MyViewController is another class MySuperViewController It is a subclass of UIViewController itself. None of these classes have a corresponding NIB; the view hierarchy is created programmatically.

I am looking for instructions on how to diagnose the problem.

< /div>

When you use the .view of the view controller directly, the view controller will most likely not receive many notifications, because It is not the correct way to use a view controller. UIWindow is a special case, because the window can automatically know the view’s controller and correctly direct messages to the controller.

But when you detach from the UIWindow When viewing the view, the view controller will also be detached and will no longer be managed by UIWindow. I think this is the source of the problem.

I suggest you add a navigation controller or a tab bar controller as the root view controller, and Use this view controller function to switch between your sub-controllers. Please note that view controllers should not be deleted when switching so that they can receive messages correctly.

If the initialization of the view controller is simple And will not consume Too much time, you might also consider releasing the view controller when not in use.

I am developing an iPhone application where many UIViews are dynamically added to the main UIWindow And removed from the main UIWindow.

When simulating a low memory error in the simulator, I found that not all view controllers receive the didReceiveMemoryWarning notification. Unfortunately, these are the most beneficial for implementation The controller for this method.

I can’t seem to find good information about where and how the method is called. I have read mention that it is sent to “all UIViewControllers”, but it is not the case. In it Adding breakpoints to a notification-receiving class is not particularly enlightening.

This is a complex project, but the ways to add these views are:

< pre>– (void) showMyView
{
if(!myViewController){
myViewController = [[MyViewController alloc]init];
[window addSubview:myViewController.view];< br /> }
}

MyViewController is a subclass of another class MySuperViewController, which itself is a subclass of UIViewController. None of these classes have a corresponding NIB; the view hierarchy is created programmatically.

I am looking for instructions on how to diagnose the problem.

When you use the view controller’s .view directly, the view controller It is very likely that you will not receive many notifications because it is not the correct way to use the view controller. UIWindow is a special case because the window can automatically know the view controller and correctly direct the message to the controller.

However, when you detach the view from the UIWindow, the view controller is also detached and is no longer managed by the UIWindow. I think this is the source of the problem.

I suggest you add a navigation controller or label The bar controller acts as the root view controller and uses the view controller function to switch between your child controllers. Please note that view controllers should not be deleted when switching so that they can receive messages correctly.

< p>If the initialization of the view controller is simple and does not consume too much time, you may also consider releasing the view controller when not in use.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1032 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.