0

XcodeでiPhone 6シミュレーターを使用しています。ビューに単純な UITextView を追加した後、それに単語を入力します。しかし、コンソールにいくつかのエラーが見つかりました:

Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextSaveGState: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextDrawLinearGradient: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextSetFillColorWithColor: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextFillRects: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextFillRects: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextSetFillColorWithColor: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextFillRects: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextSaveGState: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextDrawLinearGradient: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextSetFillColorWithColor: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextFillRects: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextFillRects: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextSetFillColorWithColor: invalid context 0x0
Oct 19 10:07:14 localhost textViewTest[1438] <Error>: CGContextFillRects: invalid context 0x0

また、メモリ使用量を見ると、非常に速く増加しますが、iphone5 または iphone4.3 シミュレータを使用すると表示されません。

これが私のコードです:

#import "ViewController.h"
#include <sys/sysctl.h>
#include <mach/mach.h>
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UITextView *textView=[[UITextView alloc] initWithFrame:CGRectMake(0,0,320,50)];
    [self.view addSubview:textView];
    [textView release];

    NSTimeInterval timeInterval =5.0 ;
    [NSTimer scheduledTimerWithTimeInterval:timeInterval
                                 target:self
                               selector:@selector(handleMaxShowTimer:)
                               userInfo:nil
                                repeats:YES];

}
- (double)availableMemory
{
    vm_statistics_data_t vmStats;
    mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
    kern_return_t kernReturn = host_statistics(mach_host_self(),HOST_VM_INFO,(host_info_t)&vmStats,&infoCount);
    if(kernReturn != KERN_SUCCESS)
    {
        return NSNotFound;
    }
    return ((vm_page_size * vmStats.free_count) / 1024.0) / 1024.0;
}

- (double)usedMemory
{
    task_basic_info_data_t taskInfo;
    mach_msg_type_number_t infoCount = TASK_BASIC_INFO_COUNT;
    kern_return_t kernReturn = task_info(mach_task_self(),
                                     TASK_BASIC_INFO, (task_info_t)&taskInfo, &infoCount);
    if(kernReturn != KERN_SUCCESS) {
        return NSNotFound;
    }
    return taskInfo.resident_size / 1024.0 / 1024.0;
}

-(void)handleMaxShowTimer:(NSTimer *)theTimer
{
    NSLog(@" use memory  %f  remain memory  %f",[self usedMemory],[self availableMemory]);

}
@end
4

1 に答える 1

0

ほとんどの場合、メモリ使用量は「狂ったように増加」しているのではなく、たまたま機器に割り当てられているバイトの総数を確認しているだけです。これは着実に増加することを意味します。実際のリークツールを使用すると、リークが発生したコードの正確な行と、特定の関数が全体的なリークにどの程度寄与しているかがわかります。

CG ...エラーに関しては、コードの描画は-drawRect:オーバーライドで実行する必要があります。これは、NULL以外の安定したコンテキストを描画できる唯一の場所です。

于 2012-10-19T02:47:10.393 に答える