gpt4 book ai didi

iphone - 我的retainCount 增加了?

转载 作者:行者123 更新时间:2023-12-03 20:17:39 25 4
gpt4 key购买 nike

我尝试在这里构建RSS阅读器,当用户读完文章并按回时,dealloc不会被调用的问题

我得到了retainCount 6,有时甚至是7!

我有很多定制面板

当按下后退按钮时, View 会弹出并且没有调用 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];

最佳答案

我发现跟踪保留计数和丢失保留-释放对的最佳方法是使用仪器。点击配置文件 (Cmd ⌘+I) 并选择Leaks模板。即使不会自动发现泄漏,也会记录保留更改,以便您可以手动跟踪其他保留。为此,请在选择分配工具时在对象摘要中找到您的类名称。如果找不到它,则意味着所有实例都已释放。否则,单击选择类名称时出现的箭头: Select the class name and click on the arrow to view living instances 您将看到您类(class)的所有事件实例: Select the instance and click on the arrow to view its retains/releases

如果您认为某些实例应该已经释放,请选择一个实例并单击对象地址旁边出现的箭头。现在,您应该看到使用执行此操作的方法名称对此对象调用的任何保留或释放: Double click to see what line of code invoked this retain/release

RefCt 列显示调用操作后的保留计数,当您双击任何保留/释放时,仪器将显示执行此操作的代码行: Responsible lines are highlighted

如您所见,对象被添加到数组中并且永远不会从数组中删除。

根据我的经验,这是查找Leaks工具无法自动检测到的内存泄漏的最快、最简单的方法。我认为另一个好的做法是查看对象摘要中的#Living,以确保事件实例的数量完全符合您的预期。

关于iphone - 我的retainCount 增加了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7695425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com