Xcode4.5 インスタンス変数の生成と解放

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
marucom311

Xcode4.5 インスタンス変数の生成と解放

#1

投稿記事 by marucom311 » 13年前

Xcode4.5 で iPhoneアプリを製作中ですが、広告を実装したところ落ちるようになりました。

-[NADView retain]: message sent to deallocated instance
というエラーメッセージが出ます。

どうも、生成したインスタンスの解放がうまくいってないようなのですが、チュートリアル等をいくら読んでも解答が見つけられませんでした。

「autoreleaseされたオブジェクトにreleaseを送ってはいけない。」という鉄則
から考えると必要なさそうな箇所があるのですが、チュートリアル等では必須なので削除をためらっています。

コードを下記に記載しますので、何か解決策はありませんでしょうか?

コード:


//.h

#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import "GADBannerView.h"
#import "NADView.h"


@interface Menue2ViewController : UITableViewController<UITableViewDataSource, UITableViewDelegate,NADViewDelegate>
{
    UITableView *_tableView;
    NADView *nadView_;
    NSArray *dataMain1;
    NSArray *dataDetail1;
    GADBannerView *bannerView_;
    
}

@property (nonatomic, retain) UITableView *_tableView;
@property (nonatomic, retain) NADView *nadView_;
@property (nonatomic, retain) GADBannerView *bannerView_;


@end

//.m
#define MY_BANNER_UNIT_ID @"*************";

@synthesize _tableView;
@synthesize nadView_;
@synthesize bannerView_;



- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 50;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    
    // (2) NADView の作成
    nadView_ = [[NADView alloc] initWithFrame:CGRectMake(0,0,
                                                         NAD_ADVIEW_SIZE_320x50.width, NAD_ADVIEW_SIZE_320x50.height )];
    // (3) set apiKey, spotId.
    [nadView_ setNendID:@"a6eca9dd074372c898dd1df549301f277c53f2b9" spotID:@"3172"];
    //⬆テスト用
    [nadView_ setDelegate:self]; //(4)
    [nadView_ setRootViewController:self]; //(5)
    [nadView_ load:nil]; //(6)
    //例) 問い合わせエラー時には 60秒間隔で再問い合わせする
    // [nadView_ load:[NSDictionary dictionaryWithObjectsAndKeys:@"60", @"retry", nil]];
    [self.view addSubview:nadView_]; // 最初から表示する場合
    
    return nadView_;
    
}

- (void) dealloc {  //この部分に不安要素があります。
    _nadView.delegate = nil;
     [_nadView release];

    [super dealloc];

}

-(void)nadViewDidFinishLoad:(NADView *)adView {
    NSLog(@"NENDLoad成功");
}

-(void)nadViewDidReceiveAd:(NADView *)adView {
    NSLog(@"NEND取得成功");
}

-(void)nadViewDidFailToReceiveAd:(NADView *)adView {
    NSLog(@"NEND取得失敗");
    nadView_.hidden = YES;
    
}

何かありましたらヒントでもかまいませんのでご教授いただけたらと思います。

アバター
h2so5
副管理人
記事: 2212
登録日時: 15年前
住所: 東京
連絡を取る:

Re: Xcode4.5 インスタンス変数の生成と解放

#2

投稿記事 by h2so5 » 13年前

最近Objective-Cをあまり触っていないので自身はないですが、
viewForFooterInSectionって複数回呼ばれる可能性がありますよね。

すると何度も[NADView alloc]されるのでメモリリークが起きてしまいます。
落ちる原因かどうかは分かりません。

閉鎖

“C言語何でも質問掲示板” へ戻る