Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8709763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:26:46+00:00 2026-06-13T04:26:46+00:00

I use iPhone 6 simulator in Xcode. After I add a simple UITextView in

  • 0

I use iPhone 6 simulator in Xcode. After I add a simple UITextView in my view, I type some word in it. But I found some errors in console:

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

And when I watch the memory use ,it increase very fast.But when I use iphone5 or iphone4.3 Simulator it will not appear.

Here is my code:

#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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:26:47+00:00Added an answer on June 13, 2026 at 4:26 am

    Your memory usage most likely isn’t “increasing like crazy”, you just happen to be looking at the total number of bytes allocated in instruments, which is meant to steadily increase. Use the actual leaks tool and it will even tell you the exact line of code the leaks occur at, and how much one particular function is contributing to the overall leakage.

    As for the CG… Errors, drawing code needs to be done in a -drawRect: override, which is the only place you can get a stable non-NULL context to draw into.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with some NSDate objects, and well, I use my iPhone with 24
I am debugging an Iphone program with the simulator in xCode and I have
I recently updated xcode to 4.2 and my iphone 3gs that I use for
Is it possible to actually use the Xcode debugger when running an iPhone app
I have created a simple Xcode 4.2 project with a empty view controller. I
Anybody else having trouble with the 4.3 iPhone Simulator in XCode 4.2(lion) or 4.0.2?
I'm trying to build an xcode project and run it through the iPhone Simulator
I'm unable to build a very simple program when building for the iPhone simulator.
I don't know why, but after a while working without problems I added some
I'm using XCode version 3.1.2 and am developing for iPhone using the Simulator with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.