-->

Layout Memory leak?

2019-08-12 15:15发布

问题:

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.

回答1:

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.