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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:55:00+00:00 2026-06-05T12:55:00+00:00

I have a UIView subclass, and within this I call this other UIView subclass.

  • 0

I have a UIView subclass, and within this I call this other UIView subclass.

Stars.h

@interface Stars : UIView {

    BOOL _gained;

}

@property (nonatomic, weak) id<NSObject> delegate;
@property (nonatomic) BOOL gained;

-(void)animateAndRemove;

@end

Stars.m

#import "Stars.h"

@implementation Stars

@synthesize delegate = _delegate;
@synthesize gained = _gained;

- (id)initWithFrame:(CGRect)frame
{
    frame.size.width = 31;
    frame.size.height = 30;
    self = [super initWithFrame:frame];
    if (self) {
        _gained = NO;
        self.backgroundColor = [UIColor clearColor];

        // Add star
        UIImageView *star = [[UIImageView alloc] initWithFrame:frame];
        [star setImage:[UIImage imageNamed:@"star-sticker"]];
        [self addSubview:star];

    }
    return self;
}

- (void)animateAndRemove
{
    [UIView animateWithDuration:0.2
                          delay:0
                        options:UIViewAnimationOptionCurveLinear
                     animations:^{
                         CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI);
                         self.transform = transform;
                     }
                     completion:^(BOOL finished){
                         [UIView animateWithDuration:0.3
                                               delay:0
                                             options:UIViewAnimationOptionCurveLinear
                                          animations:^{
                                              CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI);
                                              self.transform = transform;
                                              CGAffineTransform move = CGAffineTransformMakeTranslation(0, -200);
                                              self.transform = move;
                                              self.alpha = 0.0;
                                          }
                                          completion:^(BOOL finished){
                                              if ([self.delegate respondsToSelector:@selector(removeStar:)]) {
                                                  [self.delegate performSelector:@selector(removeStar:) withObject:self];
                                              }
                                          }];
                     }];
}

- (void)dealloc
{
    NSLog(@"%s",__FUNCTION__);
}

@end

This simply adds an image, which I animate before removing.
I add this to the original UIView like this:

star1 = [[Stars alloc] init];
star1.center = self.center;
star1.delegate = self;
[self addSubview:star1];

And start the removal process with the animation like this:

if (CGRectIntersectsRect(thumbR, star1.frame)) {
        if (!star1.gained) {
            star1.gained = YES;
            [star1 animateAndRemove];
        }
    }

Which when complete calls this:

- (void)removeStar:(Stars *)star
{
    star.delegate = nil;
    [star removeFromSuperview];
    star = nil;
}

Now the NSLog in dealloc isn’t called when the class is removedFromSuperview and set to nil. Why not?

I’m actually seeing the same thing with the first UIView that i’m loading this Stars class into. That one is also not dealloc’ing when I think it should.
Both dealloc methods are intact called when I reassign the containing UIView by alloc and initing it again.

Am I wrong to expect this to dealloc when it’s been removed from view and set to nil?

  • 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-05T12:55:02+00:00Added an answer on June 5, 2026 at 12:55 pm

    Consider your removeStar:

    - (void)removeStar:(Stars *)star
    {
       star.delegate = nil;
       [star removeFromSuperview];
       star = nil;
    }
    

    This must be called from somewhere using a call along the lines of:

    [<some object reference> removeStar:<some Stars reference>]
    

    Now the variable star in removeStar is local to that method. When the method is called this variable is initialized to the passed in Stars reference – so you have an additional reference. over and above the reference the caller of removeStar has, to the Stars instance the method is called with.

    When you then assign nil to this local variable you only remove this additional reference. The caller of removeStar still has its reference. So no dealloc.

    Guessing: The caller of removeStar is probably the owner of the instance and needs to remove its reference as well.

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

Sidebar

Related Questions

I have a custom subclass of UIView, LineDrawingView. I have this as a @property
I have a UIView subclass ( CustomView for purposes of this question) that has
I have a UIView subclass. This subclass has multiple subviews. Is it possible to
I'm creating an app where within a UIView subclass I have several UIImageView 's
I have a custom UIView subclass without a corresponding UIViewController. I use this class
I have a UIView subclass that draws a curved line within it's frame (using
I have a UIView with it's subclass set in interface builder to a UIView
I have a UIView subclass that draws a simple rectangle with this code: -
Let's say we have this part of code for a UIView subclass: self.myImage =
I have a custom UIView subclass. I am loading this through [[NSBundle mainBundle] loadNibNamed:@

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.