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

RetainCycle issue! #73

Open
omidgolparvar opened this issue Aug 30, 2019 · 11 comments
Open

RetainCycle issue! #73

omidgolparvar opened this issue Aug 30, 2019 · 11 comments

Comments

@omidgolparvar
Copy link

I used this library in a project, and I realized that viewControllers that presented by Jelly, will NOT deinitialized!

I just added this, to Example project of the library:

// DismissMeController.swift
class DismissMeController: UIViewController {

    deinit {
        print("DismissMeController.Deinit?!")
    }
    ...
}

the message is NOT printing after dismissing viewController.

@ymkim50
Copy link
Contributor

ymkim50 commented Oct 1, 2019

I also had the same problem.
I think I have a strong reference to UIViewContorller in Jelly.Animator.prepare. Therefore, it is necessary to examine whether it can be converted into weak reference.

Then the following solution could solve the problem.

/// Parent UIViewController
class ParentViewController: UIViewController, DismissMeControllerDelegate {
var animator: JellyAnimator?

func showViewController() {
    let dismissMeController = DismissMeController()
    dismissMe
    
   var presentation = Jelly.SlidePresentation()
   presentation.showDirection = .right
  
    animator = Jelly.Animator(presentation: presentation)
   animator?.prepare(presentedViewController: dismissMeController)

  present(dismissMeController, animated: true)
}

func DismissMe(_ controller: DismissMeController) {
    controller.dismiss(animated: true) {
        // Import assign nil for strong reference
        self.animator = nil
    }
}
}

// DismissMeController.swift
protocol DismissMeControllerDelegate: class {
  func dismissMe(_ controller: DismissMeController)
}

class DismissMeController: UIViewController {

    deinit {
        print("DismissMeController.Deinit?!")
    }
    

    func dismissMe() {
        delegate?.dismissMe(self)
    }
}

@Strobocop
Copy link

Same issue here. Also not sure, but I think the workaround above would not necessarily work in the case where the view controller is interactively dismissed by the user.

@ymkim50
Copy link
Contributor

ymkim50 commented Oct 5, 2019

In my case, Jelly.Animator has retain pointer to UIViewController in prepare() function.
So, Jelly.Animator must be nil after dismissed UIViewController.

@SebastianBoldt
Copy link
Owner

Hey Guys, thanks for your Feedback. I will take a look into this if i am healty again.

@ymkim50
Copy link
Contributor

ymkim50 commented Oct 6, 2019

I didn't know you had a health problem. I hope your health will be restored. Thank you for providing a good library.

@SebastianBoldt
Copy link
Owner

I am working on it ... currently not 100% sure what causes the cycle.

@peterpaulis
Copy link

this is still an issue also in 2022

@peterpaulis
Copy link

peterpaulis commented May 5, 2022

looks like

public class Animator: NSObject {
    private var presentation: Presentation
    
    private var currentPresentationController: PresentationController!

that currentPresentationController needs to be weak for the cycle to break

@peterpaulis
Copy link

peterpaulis commented Feb 26, 2024 via email

Repository owner deleted a comment from jidalii Feb 26, 2024
@SebastianBoldt
Copy link
Owner

Deleted it

@StainlessStlRat
Copy link

Is this still an issue? Any work around? Seems if it's just setting a variable to weak we could make a PR for Sebastian?

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

No branches or pull requests

7 participants
@ymkim50 @peterpaulis @SebastianBoldt @omidgolparvar @Strobocop @StainlessStlRat and others