ベースの絵本のベースのページごとに、個別.h
の 、.m
、およびファイルを使用しています。各ページにはアニメーション、音楽などが読み込まれ、約 4MB のメモリが必要です。Instruments では、各ページが読み込まれるたびに空きメモリが約 4MB 減少します。このメモリは、ページがめくられても決して解放されません。最終的にメモリ警告が表示されます。 インスタンス化された各ページをメモリに保持し、アンロードしないようです。そのため、ページが高速でめくられると、アプリがクラッシュします。.xib
UIViewController
UIPageViewController
UIPageViewController
UIPageViewController
前のページ、現在のページ、次のページの 3 つを除いて、すべてのページをアンロードできるようにしたいと考えています。によってインスタンス化された不要なページをアンロードするにはどうすればよいですかUIPageViewController
。
UIPageViewController
以下は、プルするページの配列です。すべてのページ (Page1、Page2 など) は基本的に、画像ファイルをロードし、基本的なアニメーションを提供し、音楽を追加するだけです。
//ARRAY OF PAGES
pageArray = [[NSArray alloc] initWithObjects:
(id)[[Page1 alloc] initWithNibName:nil bundle:nil],
[[Page2 alloc] initWithNibName:nil bundle:nil],
[[Page3 alloc] initWithNibName:nil bundle:nil],
[[Page4 alloc] initWithNibName:nil bundle:nil],
[[Page5 alloc] initWithNibName:nil bundle:nil],
[[Page6 alloc] initWithNibName:nil bundle:nil],
[[Page7 alloc] initWithNibName:nil bundle:nil],
[[Page8 alloc] initWithNibName:nil bundle:nil],
// continues all the way up to page 47
[[Page47 alloc] initWithNibName:nil bundle:nil],
nil];
の標準的な初期化は省略しましたUIPageViewController
。「 」を使用nextPageNumber
して上から右のページをプルしpageArray
、新しいページ オブジェクトを作成します。
-(void)turnPageForward{
[pageController setViewControllers:[NSArray arrayWithObject:[pageArray objectAtIndex:nextPageNumber]]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES completion:^(BOOL finished){
}];
}
pageIndex
に提供した後に nil に設定されるオブジェクト " " (以下を参照) を作成しようとしましたpageController
。うまくいきませんでした。ページが進んだ後も、ページはまだ十分にメモリを占有していました。
//PROGRAM PAGE FORWARD
-(void)turnPageForward{
UIViewController * pageIndex =[pageArray objectAtIndex:nextPageNumber]; //nextPageNumber is the next page to load
[pageController setViewControllers:[NSArray arrayWithObject:pageIndex]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES completion:^(BOOL finished){
}];
pageIndex = nil;
}
にページを提供するのと同じ方法を使用して投稿のスタックオーバーフローを調べましたがUIPageViewController
、近いものは見つかりませんでした。最も近いのは「ナビゲーションコントローラーで「戻る」ときにARCがメモリを解放しない」でしたが、ビューコントローラーを同じように設定しません。
望ましくないページを nil に設定しようとしたので、ARC はそれらを運良く削除できます。試してみるべき提案や代替パスはありますか? 私はページのカール効果が好きで、水平方向のページのカールを行う良いものを他に見つけることができませんでした.
ありがとう!エリック