티스토리 뷰
Stackoverflow 를 둘러보던 중,
아래와 같은 글을 발견했다.
Java 에서 try-catch 로 OutOfMemoryError 를 잡을 수 있나??
아니 어떻게 OS 단에서 컨트롤 하는 메모리에러를 잡지? 라고 생각하며 스크롤을 내렸는데..
잡을수 있다??
안드로이드로 테스트를 한번 해보기로 했다..
1. OutOfMemory Generator
2. 실행
TestModel tm = new TestModel();
try {
tm.generateOOM();
} catch (OutOfMemoryError e) {
android.util.Log.d(null, "==================> " + e.toString());
}
3. 결과
01-05 15:11:09.693 11900-11900/? D/Leeyoungwoo1: =================> OOM test started..
01-05 15:11:09.693 11900-11900/? D/Leeyoungwoo1: Iteration 1 Free Mem: 430730
01-05 15:11:09.693 11900-11900/? D/Leeyoungwoo1: Required Memory for next loop: 100
01-05 15:11:10.693 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Iteration 2 Free Mem: 410378
01-05 15:11:10.693 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Required Memory for next loop: 500
01-05 15:11:11.693 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Iteration 3 Free Mem: 409962
01-05 15:11:11.693 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Required Memory for next loop: 2500
01-05 15:11:12.694 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Iteration 4 Free Mem: 407754
01-05 15:11:12.694 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Required Memory for next loop: 12500
01-05 15:11:13.695 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Iteration 5 Free Mem: 395306
01-05 15:11:13.699 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Required Memory for next loop: 62500
01-05 15:11:14.700 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Iteration 6 Free Mem: 341898
01-05 15:11:14.703 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Required Memory for next loop: 312500
01-05 15:11:15.705 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Iteration 7 Free Mem: 2407306
01-05 15:11:15.707 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Required Memory for next loop: 1562500
01-05 15:11:16.708 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Iteration 8 Free Mem: 1150506
01-05 15:11:16.709 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Required Memory for next loop: 7812500
01-05 15:11:17.710 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Iteration 9 Free Mem: 6406032
01-05 15:11:17.713 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Required Memory for next loop: 39062500
01-05 15:11:18.713 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Iteration 10 Free Mem: 16758488
01-05 15:11:18.714 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Required Memory for next loop: 195312500
01-05 15:11:19.714 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: Iteration 11 Free Mem: 16746560
01-05 15:11:19.889 11900-11900/jcompia.com.mvppatterntest D/Leeyoungwoo1: ==================> java.lang.OutOfMemoryError: Failed to allocate a 781250012 byte allocation with 16777216 free bytes and 39MB until OOM
헐.....????
catch 안에 OOM도 잡히고..
앱도 안튕김......
결론 : Java OOM 은 Try-catch 로 잡을 수 있다.
'기타 > 궁금증테스트' 카테고리의 다른 글
(MySQL) Auto increment 에 manually 값을 지정해 넣으면? (0) | 2017.06.27 |
---|---|
( Java ) 싱글코어에서 무한루프를 돌리면 CPU 를 다 쓸까? (1) | 2017.05.23 |
(iOS) LTE, 3G 셀룰러 데이터를 꺼도 전화, 문자가 가능한가? (0) | 2017.05.23 |
- Total
- Today
- Yesterday
- Swift
- Android
- Phaser
- 점유율
- php
- GIT
- Kotlin
- Asterisk
- xcode
- linux
- 앵커브리핑
- IOS
- 리눅스
- mysql
- 손석희
- git hub
- nodejs
- 안드로이드
- 뉴스룸
- 배열
- CentOS
- C
- 깃헙
- 스위프트
- Node
- 노드
- 서버
- node.js
- BBC 가쉽
- C언어
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |