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 7128067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:05:59+00:00 2026-05-28T11:05:59+00:00

I have problem with my app. It is developed for both devices. On iPad

  • 0

I have problem with my app. It is developed for both devices. On iPad it works great, but if I run it on iPhone it sucks. It slows down a lot. Note:I use storyboards and same View controllers and delegates for both devices.

Any suggestions?

Is drawRect —- leaking memory

It is iOS 5, On iPhone 3, 3S, 4, and 4S. Everyone is experiencing problems with this.
It draws in response to finger movement.
If I touch the screen, the line I draw falls behind….. and I don’t know why.
On iPad it works great .

maybe but main there could be problem here

- (void)drawRect:(CGRect)rect
{

    CGImageRef cgImage = CGBitmapContextCreateImage(offScreenBuffer);
    UIImage *uiImage = [[UIImage alloc] initWithCGImage:cgImage];

    CGImageRelease(cgImage);

    [uiImage drawInRect:self.bounds];
    [uiImage release];

}

this method is called from touches events …

-(void)drawPoint:(UITouch *)touch {

currentLoc = [[PointLocation alloc] init];

currentLoc.location = [touch locationInView:self];

self.previousPoint = self.point;

self.point = currentLoc;
[self drawToBuffer];

[currentLoc release];
}

and this is draw to buffer….

-(void)drawToBuffer {

CGFloat color[4] = {R,G,B,A};

if (self.previousPoint != nil) {
    CGContextSetRGBStrokeColor(offScreenBuffer, color[0],color[1],color[2],color[3]);

    CGContextBeginPath(offScreenBuffer);
    CGContextSetLineWidth(offScreenBuffer, lane);
    CGContextSetLineCap(offScreenBuffer, kCGLineCapRound);

    CGContextMoveToPoint(offScreenBuffer, previousPoint.location.x, previousPoint.location.y);
    CGContextAddLineToPoint(offScreenBuffer, point.location.x, point.location.y);

    CGContextDrawPath(offScreenBuffer, kCGPathStroke);

}
 [self setNeedsDisplay];
}

but now i really don’t know and have no idea…:(

creating offscreenbuffer
-(CGContextRef)setupBuffer {

CGSize size = self.bounds.size;

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

CGContextRef context = CGBitmapContextCreate(NULL, size.width, size.height, 8, size.width*4, colorSpace, kCGImageAlphaPremultipliedLast);


CGColorSpaceRelease(colorSpace);

CGContextTranslateCTM(context, 0, size.height);
CGContextScaleCTM(context, 1.0, -1.0);


return context;

}

  • 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-05-28T11:06:00+00:00Added an answer on May 28, 2026 at 11:06 am

    You can cut a few corners by drawing the CGImage directly, without the UIImage step, using

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextDrawImage(context, self.bounds, cgImage);
    

    this will probably flip the image vertically, but that can be fixed. It may or may not make a difference, I don’t know what overhead UIImage adds.

    As for strange performance differences, you may want to look into the memory alignment of the underlying bitmap. (see the comments for my question regarding offscreenBuffer)

    update regarding the code shown in the updated question

    The code is not really efficient. For every touch event, you have this happening:

    1. a call to -drawPoint:
    2. allocation, init, release and dealloc of PointLocation, assignment using setter (self.point = ...)
    3. a call to -drawToBuffer
    4. setting stroke color/line style/line cap on your offscreen context
    5. beginpath, movetopoint, addlinetopoint, drawpath

    these may each not take a lot of time, but added together it might just make a difference if you would reduce the complexity. Per item you can try the following:

    1. reduce the number of calls, by doing some stuff directly in/from the touch event functions
    2. don’t box the CGPoint in an object, but just use two CGPoint ivars instead of properties. So it will look like: lastPoint = currPoint; currPoint = point;, with the rest of the code adapted of course
    3. see point 1.
    4. if you keep the same CGContext backing throughout the lifecycle of the view, you only need to set these once on initialization. Otherwise, if you do need to switch styles once in a while, use CGContextSaveGState(offscreenBuffer) and CGContextRestoreGState(offscreenBuffer) to see if it is faster
    5. there is a neat function for just drawing a simple line: CGContextStrokeLineSegments, which may be faster. Use it like this:

      CGPoint points[2] = { lastPoint, currPoint };
      CGContextStrokeLineSegments(offscreenBuffer,points,2);

    6. profile/profile/profile: test to see if changes make things faster, by measuring rendering time. At the top: NSDate *tstart = [NSDate date]; and at the bottom NSLog(@"drawRect took %f ms",-[tstart timeIntervalSinceNow]*1000);

    You can tackle each of these points individually and check if it still works.

    Good luck!

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

Sidebar

Related Questions

I have problem with Timeout, when I run a command through app, a timeout
Recently we've developed an iPhone app for an external company, and everything works fine
I have developed an Android app which I want to be available both as
I'm developing an android app, and have developed a game, but I now have
Hello I am a Java web app developer I have a problem, I would
i still have a problem to develop a convenient app to the user. because
I have a curious problem: My app is distributed through ClickOnce. I recently installed
I have problem in declaring the intents on my app. I have a form
I'm writing an app in Visual Studio C++ and I have problem with assigning
I'm developing small FTP upload app. for mac (10.6 if it matters) Have problem

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.