Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change property timeLabel from strong to weak to avoid reatin cycle. #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

szupzj18
Copy link

I used this amazing label for my project, it's perfect for my requirements (😄 thanks, bro.) , but I found that the timeLabel property might have retain cycle issue.

- (UILabel*)timeLabel {
    if (_timeLabel == nil) {
        _timeLabel = self;
    }
    return _timeLabel;
}

when no specific UILabel object was passed into this object, it will make the timeLabel pointer point to itself ( which is strong assignment), cause the retain cycle.
I tested on my device and that is the case.

I make a demo view controller and add this label as a subview of it.
when I quit the demo view controller. The object still exist on mem graph, which means mem leak (caused by the ivar: _timeLabel)
CleanShot 2023-05-15 at 23 08 53@2x

if I make it weak property, it will dealloc properly.
CleanShot 2023-05-15 at 23 10 54@2x

(I re-opened this pr, because I forgot to create a new branch lol.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant