예를들어 LinearLayout 을 하나 생성하고
거기에 new 로 Button 10개를 생성해서 Addview 해놓은 상태라면
LinearLayout 에 10개의 Button 이 표시가 되자나요.. 그런데 여기서
Linearlayout 에 removeAllView 를 해주게되면 차일드뷰인 Button 10개가
모두 사라지면서 메모리에서도 모두 제거가 되는건가요???
내부적으로는 child view들을 null 처리 하고는 있지만,
실제로 메모리상에서 제거가 되는지는 명확히 알기 어렵습니다.
다른 곳에서 참조하고 있지만 않으면 GC가 동작할 때 메모리에서 날아갈 거에요.
public void removeAllViewsInLayout() {2275 final int count = mChildrenCount;2276 if (count <= 0) {2277 return;2278 }22792280 final View[] children = mChildren;2281 mChildrenCount = 0;22822283 final OnHierarchyChangeListener listener = mOnHierarchyChangeListener;2284 final boolean notify = listener != null;2285 final View focused = mFocused;2286 final boolean detach = mAttachInfo != null;2287 View clearChildFocus = null;22882289 needGlobalAttributesUpdate(false);22902291 for (int i = count - 1; i >= 0; i--) {2292 final View view = children[i];22932294 if (view == focused) {2295 view.clearFocusForRemoval();2296 clearChildFocus = view;2297 }22982299 if (view.getAnimation() != null) {2300 addDisappearingView(view);2301 } else if (detach) {2302 view.dispatchDetachedFromWindow();2303 }23042305 if (notify) {2306 listener.onChildViewRemoved(this, view);2307 }23082309 view.mParent = null;2310 children[i] = null;2311 }23122313 if (clearChildFocus != null) {2314 clearChildFocus(clearChildFocus);2315 }2316 }
public void removeAllViewsInLayout() {
2275
final int count = mChildrenCount;
2276
if (count <= 0) {
2277
return;
2278
}
2279
2280
final View[] children = mChildren;
2281
mChildrenCount = 0;
2282
2283
final OnHierarchyChangeListener listener = mOnHierarchyChangeListener;
2284
final boolean notify = listener != null;
2285
final View focused = mFocused;
2286
final boolean detach = mAttachInfo != null;
2287
View clearChildFocus = null;
2288
2289
needGlobalAttributesUpdate(false);
2290
2291
for (int i = count - 1; i >= 0; i--) {
2292
final View view = children[i];
2293
2294
if (view == focused) {
2295
view.clearFocusForRemoval();
2296
clearChildFocus = view;
2297
2298
2299
if (view.getAnimation() != null) {
2300
addDisappearingView(view);
2301
} else if (detach) {
2302
view.dispatchDetachedFromWindow();
2303
2304
2305
if (notify) {
2306
listener.onChildViewRemoved(this, view);
2307
2308
2309
view.mParent = null;
2310
children[i] = null;
2311
2312
2313
if (clearChildFocus != null) {
2314
clearChildFocus(clearChildFocus);
2315
2316
로그인 유지
내부적으로는 child view들을 null 처리 하고는 있지만,
실제로 메모리상에서 제거가 되는지는 명확히 알기 어렵습니다.
다른 곳에서 참조하고 있지만 않으면 GC가 동작할 때 메모리에서 날아갈 거에요.
return;mChildrenCount = 0;