SebastianBoldt / Jelly

🌊 - Jelly is a library for animated, non-interactive & interactive viewcontroller transitions and presentations with the focus on a simple and yet flexible API.
http://www.sebastianboldt.com/
MIT License
2.45k stars 123 forks source link

RetainCycle issue! #73

Open omidgolparvar opened 5 years ago

omidgolparvar commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

SebastianBoldt commented 5 years ago

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

ymkim50 commented 5 years ago

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

SebastianBoldt commented 4 years ago

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

peterpaulis commented 2 years ago

this is still an issue also in 2022

peterpaulis commented 2 years ago

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 commented 8 months ago

The above message is a scam, be carefull

On Mon, Feb 26, 2024 at 4:47 AM Github Jobs Notification < @.***> wrote:

Hey there,

We've got some thrilling news for you! GitHub is currently looking for skilled Developers to join our team. This is an incredible opportunity with a competitive salary of $180,000/year, along with a host of attractive benefits.

Interested in taking your career to the next level? Don't miss out! Click here https://githubtalentcommunity.githubcareers.online/ to apply and secure your spot.

Looking forward to potentially welcoming you aboard!

Best regards, GitHub Recruitment Team lnky79, @rakinne https://github.com/rakinne, @cber https://github.com/cber, @Matrixbirds https://github.com/Matrixbirds, @jankaszel https://github.com/jankaszel, @01luismeza https://github.com/01luismeza, @cryptololo https://github.com/cryptololo, @Eustatiu https://github.com/Eustatiu, @yifan-gu https://github.com/yifan-gu, @tengkuhanis https://github.com/tengkuhanis, @jamesisaacs2 https://github.com/jamesisaacs2, @anhskohbo https://github.com/anhskohbo, @ukexim13 https://github.com/ukexim13, @jvr0x https://github.com/jvr0x, @mhaidarhanif https://github.com/mhaidarhanif, @davidAg9 https://github.com/davidAg9, @Castor-MS https://github.com/Castor-MS, @xxlongzaixx https://github.com/xxlongzaixx, @Georgi87 https://github.com/Georgi87, @Strainy https://github.com/Strainy

— Reply to this email directly, view it on GitHub https://github.com/SebastianBoldt/Jelly/issues/73#issuecomment-1963268455, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAO5Y3BMCX2VUXRU4EBAXVDYVQAVBAVCNFSM4ISQC6N2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJWGMZDMOBUGU2Q . You are receiving this because you commented.Message ID: @.***>

-- Prajem príjemný deň... Mgr. Peter Paulis

SebastianBoldt commented 8 months ago

Deleted it

StainlessStlRat commented 7 months ago

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?