布局内存泄漏? [英] Layout Memory leak?

查看:291
本文介绍了布局内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个初级Android开发者。 Android的UI设计,我想大多数的Andr​​oid开发者将使用XML进行布局设计。今天,我的高级开发人员说,他不使用XML进行布局设计。所有的UI设计使用code产生。他说,原因是布局资源不是由Android automatically.Using JNI释放释放的布局资源。他没有详细告诉你,因为他觉得我很初级。

我要问他是否是真还是假。我不知道他的观点。但是,我要确保他的code不能重用。此外,如何在Android发布布局资源在其生命周期。

感谢。


解决方案

  

他说的原因是,布局资源不是由Android的自动释放


通过虚报布局资源创建的窗口小部件由Android自动释放当这些部件从活动中删除,或者如果活动被销毁。换言之,窗口小部件是垃圾收集相同的任何其他Java对象。而且,这也是如此无论小部件是使用布局资源或未创建。

可以想象布局资源的分析的XML由过程缓存,所以如果再次需要相同的布局,解析步骤可以跳过。这会不会是非常多的内存。避免XML布局资源,以避免这样的小内存缓存是非常短视的,不是我所期待的真正的高级开发人员。


  

使用JNI释放布局资源


JNI无关与布局资源。 JNI无关与部件,无论是。


  

他并没有详细告诉你,因为他觉得我很初级。


欢迎他记录他的发现,为他的主张和理由为他的决定证明。

i am a junior android developer. For android UI design, i think most of android developer will use XML for layout design. Today, my senior developer said that he does not use XML for layout design. All UI design use code to generate. The reason he said is that the layout resource is not released by Android automatically.Using JNI release the layout resource . He does not tell you in detail because he think i am very junior.

I want to ask whether he is true or not. I have no idea for his point of view. But, i make sure that his code cannot reuse. Also, how the Android release the layout resource in its life cycle.

Thanks.

解决方案

The reason he said is that the layout resource is not released by Android automatically

The widgets created by inflating a layout resource are "released by Android automatically" when those widgets are removed from the activity or if the activity is destroyed. In other words, widgets are garbage-collected the same as any other Java object. And, this holds true no matter whether the widgets were created using layout resources or not.

It is conceivable that the parsed XML of the layout resource is cached by the process, so if the same layout is needed again, the parsing step can be skipped. This will not be very much memory. Avoiding XML layout resources to avoid such small memory caching is very short-sighted, not what I would expect from a true "senior developer".

Using JNI release the layout resource

JNI has nothing to do with layout resources. JNI has nothing to do with widgets, either.

He does not tell you in detail because he think i am very junior.

He is welcome to document his findings, providing proof for his claims and justifications for his decision.

这篇关于布局内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆