Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 我的收入在增加?_Iphone_Memory_Dealloc_Retaincount_Popviewcontrolleranimated - Fatal编程技术网

Iphone 我的收入在增加?

Iphone 我的收入在增加?,iphone,memory,dealloc,retaincount,popviewcontrolleranimated,Iphone,Memory,Dealloc,Retaincount,Popviewcontrolleranimated,我在这里尝试构建rss阅读器,当用户读完文章并按下返回键时,这个问题不会被调用 我得到了重新计数6&有时是7 我有很多定制的面板 当按下“后退”按钮时,视图弹出且未调用dealloc .h文件: @interface ArticalViewController : UIViewController<UIWebViewDelegate,UIScrollViewDelegate,UIActionSheetDelegate,ArticalBottomPanelDelegate,ArticalC

我在这里尝试构建rss阅读器,当用户读完文章并按下返回键时,这个问题不会被调用

我得到了重新计数6&有时是7

我有很多定制的面板

当按下“后退”按钮时,视图弹出且未调用dealloc

.h文件:

 @interface ArticalViewController : UIViewController<UIWebViewDelegate,UIScrollViewDelegate,UIActionSheetDelegate,ArticalBottomPanelDelegate,ArticalContentFetcherDelegate> {

    UIWebView * description_;
    UIActivityIndicatorView * ind_;
    ArticalModel * artical_;
    NSString * content;
    UIButton * faceBookShareBtn_;

     UIBarButtonItem * btnSharePanel_;


     CustomTopToolBar * topToolbar_;

     ArticalBottomPanel* articalBottomPanel_;
     MovingSharePanel * movingSharePanel_;

     int fontSize;
     BOOL favoStatus;
     ArticalContentFetcher *datafetcher_;     

 }


@property (nonatomic,retain) IBOutlet UIWebView * description;
@property (nonatomic,retain ) IBOutlet UIActivityIndicatorView * ind;
@property (nonatomic,retain) ArticalModel * artical;
@property (nonatomic,retain) IBOutlet UIButton * faceBookShareBtn;


@property (nonatomic,retain) IBOutlet  CustomTopToolBar * topToolbar;
@property (nonatomic , retain) IBOutlet ArticalBottomPanel * articalBottomPanel;
@property (nonatomic , retain) IBOutlet MovingSharePanel * movingSharePanel;

@property (nonatomic , retain) ArticalContentFetcher *datafetcher;




-(void) loadArtical:(ArticalModel * )artical;
- (void) loadArticalContentFromInternet;
-(void) changeFavoriteBtnIcon:(BOOL) status;
-(void)backBtnPressed:(id) sender;

-(IBAction)openPostBtnPressed:(id)sender;

@end

NSThread detachNewThreadSelector:toTarget:withObject:保留其目标,在本例中为self。此外,self在这里是一些事情的代理,通常您不想保留代理,因此,如果您编写了这些协议,请检查您是否没有这样做。

您没有理由关心保留计数是多少。只需确保您的保留和释放保持平衡。

尽管看起来很奇怪,但重新计入对计算您的保留一点用处都没有。除了调用[myObject retain]或[[MyClass alloc]init]等,其他原因会保留这些内容


最好是忽略重新计数,并学习正确的方法。重新计算会让你更加困惑。如果您只为iOS 5开发,最好忘记内存管理和使用。

我发现跟踪保留计数和丢失的保留释放对的最佳方法是使用仪器。点击配置文件命令⌘+我选择了一个模板。即使不会自动发现泄漏,也会记录保留更改,以便您可以手动跟踪其他保留。要做到这一点,请在选中时在对象摘要中查找类名。如果您找不到它,这意味着所有实例都已解除分配。否则,单击选择类名时出现的箭头: 您将看到您的类的所有活动实例:

如果您假设有一些实例应该已经解除分配,请选择一个实例并单击对象地址旁边的箭头。现在,您应该看到在此对象上调用的任何retain或release,其方法名为执行此操作:

RefCt列显示调用操作后的retainCount,当您双击任何retain/release时,instruments将显示执行此操作的代码行:

如您所见,对象被添加到数组中,并且从未从数组中删除


根据我的经验,这是查找内存泄漏的最快、最简单的方法,而这些泄漏是仪器无法自动检测到的。我认为另一个好的做法是查看对象摘要中的活动实例,以确保活动实例的数量与您预期的完全一致。

在发送此问题之前,我查看了这里,但我询问了我的案例,我的代码出了什么问题!?是的,我检查了我的代理,现在我重新计算了2,但是在我调用[self.navigationController popViewControllerAnimated:YES]之后,保留计数是4!!我加上[自我保留];在[self.navigationController PopViewControllerInitiated:是]之前;dealloc调用正确,但调用[自我释放]是真的吗!?这就是解决办法吗?!弹出时的保留计数可能会有所不同,这取决于loadArticalContentFromInternet方法是否已在另一个线程上完成。你应该在弹出前取消此线程。漫无目的地要求释放是危险的。找出你被保留的其他地方,并适当地发布。
    #import "ArticalViewController.h"


    @implementation ArticalViewController


    @synthesize description=description_;
    @synthesize artical=artical_; 
    @synthesize ind=ind_;

    @synthesize  faceBookShareBtn=faceBookShareBtn_;

    @synthesize topToolbar=topToolbar_;
    @synthesize articalBottomPanel=articalBottomPanel_;
    @synthesize movingSharePanel=movingSharePanel_;
    @synthesize datafetcher=datafetcher_;

    - (void)dealloc
    {
        NSLog(@"ArticalViewController : dealloc");
        [description_ release];
        [ind_ release];
        [artical_ release];
        [content release];
        [faceBookShareBtn_ release];

        [btnSharePanel_ release];


        [topToolbar_ release];

        [articalBottomPanel_ release];
        [movingSharePanel_ release];
        [datafetcher_ release];

        [super dealloc];
    }

    #pragma mark -
    #pragma mark - View lifecycle

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        fontSize=100;


        [self.articalBottomPanel setDelegate:self];
        [self.movingSharePanel setArtical:self.artical];
        [self.movingSharePanel setParentView:self];


        [self.topToolbar.rightButon setFrame:CGRectMake(260 , 3,  50, 30)];
        [self.topToolbar.rightButon addTarget:self action:@selector(backBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
        [self.topToolbar.rightButon setImage:[UIImage imageNamed:@"back-button"] forState:UIControlStateNormal];

        [self.topToolbar.leftButon setFrame:CGRectMake(10 , 3,  50, 30)];
        [self.topToolbar.leftButon setImage:[UIImage imageNamed:@"button-toolbar-post-link"] forState:UIControlStateNormal];
         [self.topToolbar.leftButon addTarget:self action:@selector(openPostBtnPressed:) forControlEvents:UIControlEventTouchUpInside];


        self.topToolbar.label.text =self.artical.category;
      //  [label release];

        //Navigation Buttons
        self.navigationItem.hidesBackButton=YES;

        //Check if artical is favorited or not
        [self changeFavoriteBtnIcon:[Favorites chechArtical:self.artical]];



        [self.description setBackgroundColor:[UIColor clearColor]];
        [self.description setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"1px-post-views-background"]]];

        if([[self.artical content] length] >1){
            NSLog(@"[[self.artical content] length] >1");
           [self loadArtical:self.artical];
        }else {
            NSLog(@"else");
            self.datafetcher=[[ArticalContentFetcher alloc ]init ];
            [self.datafetcher setArticalContentFetcherDelegate:self];
             [NSThread detachNewThreadSelector:@selector(loadArticalContentFromInternet) toTarget:self withObject:nil];

        }




    }
    #pragma mark -
    #pragma mark ArticalConnectionFeed Delegate Methods
    -(void) articalContentConnectionDoneWithArtical:(ArticalModel *)artical {
        NSLog(@"articalContentConnectionDoneWithArtical");
        [self loadArtical:artical];
    }
    -(void) articalContentConnectionFailed{
        NSLog(@"articalContentConnectionFailed");

    }
    #pragma mark -
    #pragma mark ArticalBottomPanelDelegate Delegate Methods

    -(void) openPanelFired{
        NSLog(@"openPanelFired");
        [self.movingSharePanel movePanel];
      //  [self.articalBottomPanel.btnOpenSharePanel setHidden:YES];
    }

    -(void) fontBtnFired:(int)font{
       // NSLog(@"fontBtnFired : %d",font);
        if(font==1){
            [self.description stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '90%'"];
        }else {
            [self.description stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '-10%'"];
        }
    }
    -(void) favoBtnFired {
        NSLog(@"favoBtnFired");
        favoStatus=[Favorites processArtical:self.artical];
        [self changeFavoriteBtnIcon:favoStatus];
    }

    -(void) changeFavoriteBtnIcon:(BOOL) status{
        if (status){
            [self.articalBottomPanel.btnFavo setImage: [UIImage imageNamed:@"active-star.png"] forState:UIControlStateNormal];

        }else {
            [self.articalBottomPanel.btnFavo setImage: [UIImage imageNamed:@"star.png"] forState:UIControlStateNormal];
        }
    }
    #pragma mark -
    #pragma mark UIWebView Delegate Methods
    -(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
        if([InternetConnection getInternetStatus]){
            if ( inType == UIWebViewNavigationTypeLinkClicked ) {
                [[UIApplication sharedApplication] openURL:[inRequest URL]];
                return NO;
            }
            return YES;
        }else {
            [InternetConnection ShowNoInternetAlert];
            return NO;
        }


    }

    - (void)webViewDidFinishLoad:(UIWebView *)webView {
        [self.ind stopAnimating];
    }


    #pragma mark -
    #pragma mark Class Methods
    -(void) loadArtical:(ArticalModel * )artical{
        NSLog(@"loadArtical");
        [self.artical setContent:[artical content]];
        [self.artical setCategory:[artical category]];


        NSString * style=[[NSString alloc ] initWithFormat:@"<style> #offline img{display:none;} .wrap{text-align:right;line-height:22px; direction:rtl;} .title{font-size:20px;margin-bottom:5px;} .date{font-size:13px;} .cat{font-size:13px;} </style>"];

        if([InternetConnection getInternetStatus])
            NSLog(@"[InternetConnection getInternetStatus] : true");
        content=[[NSString alloc] initWithFormat:@"%@<div class='wrap' ><div class='title'>%@</div><div class='date'>%@</div><div class='cat'>%@</div>%@</div>",style,[self.artical title],[DateProcessor getInternetDateAndTimeForArticals:self.artical.pubDate],[self.artical category],[self.artical content] ];
        [ self.description loadHTMLString:content baseURL:[NSURL URLWithString:@""]];

        [style release];
    }

    - (void) loadArticalContentFromInternet{
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        [self.datafetcher loadArticlContentWithID:self.artical.ID];
        [[NSRunLoop currentRunLoop] run ];
        [pool release];


    }
    -(void)backBtnPressed:(id) sender{
            NSLog(@"backBtnPressed");

        [self.navigationController popViewControllerAnimated:YES];


    }

    #pragma mark -
    #pragma mark IBActions      


    -(IBAction)openPostBtnPressed:(id)sender{
        if([InternetConnection getInternetStatus]){
            [InternetConnection openExternalUrl:self.artical.link];
        }else{
            [InternetConnection ShowNoInternetAlert];
        }


    }

    @end
avc=[[ArticalViewController alloc]initWithNibName:@"ArticalViewController" bundle:nil];
    avc.artical=[self.feeds objectAtIndex:indexPath.row]; 
    [self.navCon pushViewController:avc animated:YES];

    [avc release];