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

The Archive Base Latest Questions

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

I wrote the following code in a file called PieChartView.m: #pragma mark DrawingDelegate @interface

  • 0

I wrote the following code in a file called PieChartView.m:

#pragma mark DrawingDelegate
@interface DrawingDelegate : NSObject
@end

@implementation DrawingDelegate

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
    //nothing here yet...
}

#pragma mark PieChartView
@implementation PieChartView

@synthesize pie_layer;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
            float pie_layer_width = 300.f;
            float pie_layer_height = 160.f;
            float pie_layer_PosX = 7.f;
            float pie_layer_PosY = 20.f;

            DrawingDelegate* layerDelegate = [[DrawingDelegate alloc] init];

            pie_layer = [[CALayer alloc] init];

            //when commenting the following assignment the app no longer crashes
            pie_layer.delegate = layerDelegate;
            pie_layer.bounds = CGRectMake( 0.f, 0.f, pie_layer_width, pie_layer_height );
            pie_layer.backgroundColor = [[UIColor whiteColor] CGColor];
            pie_layer.position = CGPointMake( pie_layer_width/2+pie_layer_PosX, pie_layer_height/2+pie_layer_PosY );
            pie_layer.cornerRadius = 10.f;
            CGFloat components[4] = { 0.0, 0.0, 0.0, 1.0 };

            CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
            CGColorRef black = CGColorCreate( colorspace, components );
            pie_layer.borderColor = black;
            pie_layer.borderWidth = 1.f;
            pie_layer.shadowRadius = 5.f;
            pie_layer.shadowColor = black;

            CGColorRelease( black );
            CGColorSpaceRelease(colorspace);

            pie_layer.shadowOffset = CGSizeMake( 0.f, 5.f ),
            pie_layer.shadowOpacity = 0.75f;
            [self.layer insertSublayer:pie_layer above:self.layer];
            [pie_layer setNeedsDisplay];
        }
        return self;
}

Strangly the app crashes as long as I execute the line “pie_layer.delegate = layerDelegate;”. The crash looks like the given screenshot.

enter image description here

Why does this happen? What is wrong in my code?

Here is another more detailed stacktrace:
enter image description here

  • 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-13T07:42:47+00:00Added an answer on June 13, 2026 at 7:42 am

    If this is ARC and the delegate is weak then the drawing delegate will be released as nothing takes ownership of it.

    Delegates by convention are weak but something needs to keep a strong reference to the DrawingDelegate object you create.

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

Sidebar

Related Questions

I wrote the following code for text file encryption and decryption. The encryption process
I wrote the following code to count the node of an XML file: private
i did the following vbscript code to write a text file called level.txt in
I have a file called: file.php contained in this file is the following code:
I wrote below dll called djj.dll it has a file called try.cpp with following
I wrote the basic code below and saved to a file called pdf.java. package
Using the following code to write to a file int main(int argc, char *
Given the following code (it's supposed to write helloworld in a helloworld file, and
I want to write a .xml file using the following code into the App_Data/posts.
When I try to open a file in write mode with the following code:

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.