2

ここでrssリーダーを構築しようとしています。ユーザーがアーティカルを読み終えて、deallocを押し戻すと、呼び出されないという問題があります。

そして私はretainCount6と時々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

.mファイル:

    #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

添加 :

私が使用したArticalを呼び出していたとき

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

    [avc release]; 
4

4 に答える 4

41

保持カウントと不足している保持とリリースのペアを追跡する最良の方法は、Instrumentsを使用することであることがわかりました。ヒット プロファイル (Cmd ⌘</kbd>+I) and choose Leaks template. Even if leaks will not be discovered automatically, retain changes are logged so you can manually trace additional retains. To do that, find your class name in Object Summary when selected Allocations instrument. If you can't find it, this means that all instances were deallocated. Otherwise click on the arrow that appears when you select class name: Select the class name and click on the arrow to view living instances You will see all living instances of your class: Select the instance and click on the arrow to view its retains/releases

すでに割り当てを解除する必要があるインスタンスがいくつかあると思われる場合は、1 つを選択し、オブジェクト アドレスの横に表示された矢印をクリックします。これで、このアクションを実行していたメソッド名でこのオブジェクトに対して呼び出された保持または解放が表示されます。 ダブルクリックして、この保持/解放を呼び出したコード行を確認します

RefCt列には、アクションが呼び出された後のretainCountが表示されます。保持/解放をダブルクリックすると、これが実行されたコード行がインストルメントに表示されます。 責任のある行が強調表示されます

ご覧のとおり、オブジェクトは配列に追加され、削除されることはありません。

私の経験では、これは、 Leaksインストゥルメントが自動的に検出しないメモリ リークを見つけるための最も速くて簡単な方法です。#Living in Object Summaryを調べて、生きているインスタンスの数が期待どおりであることを確認することも良い方法だと思います。

于 2011-10-08T11:50:38.847 に答える
9

保持カウントが何であるかを気にする理由はありません。保持と解放のバランスをとってください。

于 2011-10-08T08:08:56.513 に答える
5

奇妙に思えるかもしれretainCountませんが、保持数のカウントにはまったく役に立ちません。[myObject retain]電話など以外の理由で物事が保持されます[[MyClass alloc] init]

メモリ管理ルールを無視retainCountして学習することをお勧めします。あなたをもっと混乱させます。iOS 5 のみを対象に開発している場合は、メモリ管理を忘れてARCを使用することをお勧めします。retainCount

于 2011-10-08T10:44:20.630 に答える
0

NSThread detachNewThreadSelector:toTarget:withObject:はターゲットを保持します。この場合はselfです。また、 self はここでいくつかのデリゲートです。通常、デリゲートを保持したくないので、これらのプロトコルを作成した場合は、それを行っていないことを確認してください。

于 2011-10-08T07:53:50.903 に答える