Git Product home page Git Product logo

Comments (9)

zhouhuandev avatar zhouhuandev commented on June 15, 2024

java.lang.IllegalStateException: Binding instance cleared.

错误,目前我是这么处理的,但是感觉存在内存泄露风险

image

注释位置打开就会报以下错:

image

已经修复,可以重新拉取尝试

from basedemo.

BetterLive avatar BetterLive commented on June 15, 2024

场景是:Activity : BottomNavigationView + 多个Fragment 结构,进行切换

新的代码报了这个错:

image

from basedemo.

BetterLive avatar BetterLive commented on June 15, 2024

java.lang.IllegalStateException: Binding instance cleared.
错误,目前我是这么处理的,但是感觉存在内存泄露风险
image
注释位置打开就会报以下错:
image

已经修复,可以重新拉取尝试

试了下,报了 No binding inflated 错;

from basedemo.

zhouhuandev avatar zhouhuandev commented on June 15, 2024

java.lang.IllegalStateException: Binding instance cleared.
错误,目前我是这么处理的,但是感觉存在内存泄露风险
image
注释位置打开就会报以下错:
image

已经修复,可以重新拉取尝试

试了下,报了 No binding inflated 错;

您可以抽取一个Demo发至我的邮箱吗?或者是Create a issues branch 提交上来测试一下?

from basedemo.

BetterLive avatar BetterLive commented on June 15, 2024

目前在出差,我抽空弄一下

from basedemo.

BetterLive avatar BetterLive commented on June 15, 2024

找到原因了,是因为代码里面用了postDelayed模拟数据导致的问题:

image

去掉就好了,但是**这种情况下,应该在何处进行取消操作呢?我在 onDetach() 之前调用都会出问题**;

from basedemo.

zhouhuandev avatar zhouhuandev commented on June 15, 2024

找到原因了,是因为代码里面用了postDelayed模拟数据导致的问题:

image

去掉就好了,但是**这种情况下,应该在何处进行取消操作呢?我在 onDetach() 之前调用都会出问题**;

我觉得你应该在OnDestroy之前执行应该没有问题

你可以查看Fragment的生命周期,为了保障Fragment被销毁的时候,BindingHolder也跟着销毁,所以在 ObserverWrapper 中监听了 OnDestroy,在此之前都是没有问题的,我认为你不应该在 OnDestroyonDetach 之间还处理页面相关元素。

    override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
        if (source == owner && event == Lifecycle.Event.ON_DESTROY) {
            //  执行解绑销毁操作
            detach()
        }
    }

from basedemo.

BetterLive avatar BetterLive commented on June 15, 2024

找到原因了,是因为代码里面用了postDelayed模拟数据导致的问题:
image
去掉就好了,但是**这种情况下,应该在何处进行取消操作呢?我在 onDetach() 之前调用都会出问题**;

我觉得你应该在OnDestroy之前执行应该没有问题

你可以查看Fragment的生命周期,为了保障Fragment被销毁的时候,BindingHolder也跟着销毁,所以在 ObserverWrapper 中监听了 OnDestroy,在此之前都是没有问题的,我认为你不应该在 OnDestroyonDetach 之间还处理页面相关元素。

    override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
        if (source == owner && event == Lifecycle.Event.ON_DESTROY) {
            //  执行解绑销毁操作
            detach()
        }
    }

我的意思,要取消一些延迟操作,应该在哪里进行处理比较合适呢?比如动画的取消和释放、网络请求的取消等

from basedemo.

zhouhuandev avatar zhouhuandev commented on June 15, 2024

找到原因了,是因为代码里面用了postDelayed模拟数据导致的问题:
image
去掉就好了,但是**这种情况下,应该在何处进行取消操作呢?我在 onDetach() 之前调用都会出问题**;

我觉得你应该在OnDestroy之前执行应该没有问题
你可以查看Fragment的生命周期,为了保障Fragment被销毁的时候,BindingHolder也跟着销毁,所以在 ObserverWrapper 中监听了 OnDestroy,在此之前都是没有问题的,我认为你不应该在 OnDestroyonDetach 之间还处理页面相关元素。

    override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
        if (source == owner && event == Lifecycle.Event.ON_DESTROY) {
            //  执行解绑销毁操作
            detach()
        }
    }

我的意思,要取消一些延迟操作,应该在哪里进行处理比较合适呢?比如动画的取消和释放、网络请求的取消等

我认为你至少应该在OnDestroy之前销毁,更加推荐在onStop进行释放相关的操作(生命周期走到这里,基本上就是要销毁掉了,所以更加推荐在这里面做相关的操作),因为在ObserverWrapper 监听了 OnDestroy的时候进行清空了持有Binding。

from basedemo.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.