4

. 나는 FragmentStatePagerAdapter를 사용하고 있습니다. 나는 Universal Image Loader v.1.8.4도 사용하고 있습니다. 뷰를 페이징 할 때 힙이 커지고 결국 메모리가 부족합니다. 여기에 약간의 샘플 출력입니다 :FragmentStatePagerAdapter OutOfMemoryError를 내가 일하고 있어요 응용 프로그램에서 OutOfMemoryErrors가 실행 해요 내가 정확히 문제가 무엇인지를 해결하는 방법을 알아내는 데 어려움이있어

05-06 14:38:23.096: D/dalvikvm(29322): GC_CONCURRENT freed 187K, 5% free 7532K/7868K, paused 7ms+13ms, total 37ms 
05-06 14:38:23.176: D/dalvikvm(29322): GC_FOR_ALLOC freed 96K, 4% free 7656K/7920K, paused 17ms, total 17ms 
05-06 14:38:23.206: D/dalvikvm(29322): GC_FOR_ALLOC freed <1K, 4% free 8234K/8500K, paused 15ms, total 15ms 
05-06 14:38:23.246: D/dalvikvm(29322): GC_CONCURRENT freed 4K, 3% free 8262K/8500K, paused 5ms+5ms, total 31ms 
05-06 14:38:23.276: D/dalvikvm(29322): GC_FOR_ALLOC freed 29K, 3% free 8289K/8500K, paused 20ms, total 25ms 
05-06 14:38:23.286: D/dalvikvm(29322): GC_FOR_ALLOC freed <1K, 3% free 9342K/9556K, paused 15ms, total 15ms 
05-06 14:38:23.316: D/dalvikvm(29322): GC_CONCURRENT freed 27K, 3% free 9327K/9556K, paused 3ms+2ms, total 22ms 
05-06 14:38:24.626: D/dalvikvm(29322): GC_FOR_ALLOC freed 83K, 3% free 9462K/9696K, paused 15ms, total 16ms 
05-06 14:38:24.646: D/dalvikvm(29322): GC_FOR_ALLOC freed 3K, 3% free 10201K/10440K, paused 16ms, total 16ms 
05-06 14:38:24.666: D/dalvikvm(29322): GC_CONCURRENT freed 3K, 3% free 10214K/10440K, paused 3ms+3ms, total 26ms 
05-06 14:38:24.976: D/dalvikvm(29322): GC_FOR_ALLOC freed 68K, 3% free 10291K/10508K, paused 16ms, total 17ms 
05-06 14:38:24.986: D/dalvikvm(29322): GC_FOR_ALLOC freed <1K, 2% free 11297K/11516K, paused 15ms, total 15ms 
05-06 14:38:25.016: D/dalvikvm(29322): GC_CONCURRENT freed 8K, 2% free 11305K/11516K, paused 3ms+4ms, total 24ms 
05-06 14:38:25.346: D/dalvikvm(29322): GC_CONCURRENT freed 74K, 2% free 12458K/12680K, paused 2ms+3ms, total 23ms 
05-06 14:38:25.976: D/dalvikvm(29322): GC_FOR_ALLOC freed 151K, 3% free 13485K/13792K, paused 22ms, total 22ms 
05-06 14:38:26.276: D/dalvikvm(29322): GC_CONCURRENT freed 95K, 2% free 15384K/15636K, paused 3ms+3ms, total 26ms 
05-06 14:38:27.196: D/dalvikvm(29322): GC_FOR_ALLOC freed 222K, 3% free 17111K/17484K, paused 24ms, total 24ms 
05-06 14:38:28.446: D/dalvikvm(29322): GC_FOR_ALLOC freed 247K, 2% free 19784K/20180K, paused 22ms, total 22ms 
05-06 14:38:29.396: D/dalvikvm(29322): GC_FOR_ALLOC freed 248K, 2% free 23137K/23540K, paused 23ms, total 24ms 
05-06 14:38:30.976: D/dalvikvm(29322): GC_FOR_ALLOC freed 391K, 2% free 27770K/28308K, paused 29ms, total 29ms 
05-06 14:38:33.366: D/dalvikvm(29322): GC_CONCURRENT freed 516K, 2% free 33964K/34628K, paused 3ms+6ms, total 45ms 
05-06 14:38:36.126: D/dalvikvm(29322): GC_FOR_ALLOC freed 608K, 2% free 41164K/41920K, paused 37ms, total 37ms 
05-06 14:38:38.396: D/dalvikvm(29322): GC_CONCURRENT freed 598K, 2% free 48739K/49484K, paused 4ms+10ms, total 59ms 
05-06 14:38:41.496: D/dalvikvm(29322): GC_CONCURRENT freed 723K, 2% free 56176K/57044K, paused 2ms+13ms, total 71ms 
05-06 14:38:41.496: D/dalvikvm(29322): WAIT_FOR_CONCURRENT_GC blocked 62ms 
05-06 14:38:45.176: I/dalvikvm-heap(29322): Clamp target GC heap from 69.393MB to 64.000MB 
05-06 14:38:45.176: D/dalvikvm(29322): GC_FOR_ALLOC freed 597K, 2% free 62724K/63476K, paused 56ms, total 56ms 
05-06 14:38:45.936: I/dalvikvm-heap(29322): Clamp target GC heap from 71.379MB to 64.000MB 
05-06 14:38:45.936: D/dalvikvm(29322): GC_FOR_ALLOC freed 216K, 1% free 64758K/65412K, paused 50ms, total 50ms 
05-06 14:38:45.996: I/dalvikvm-heap(29322): Clamp target GC heap from 71.338MB to 64.000MB 
05-06 14:38:45.996: D/dalvikvm(29322): GC_BEFORE_OOM freed 43K, 2% free 64714K/65412K, paused 60ms, total 60ms 
05-06 14:38:46.336: I/dalvikvm-heap(29322): Clamp target GC heap from 71.462MB to 64.000MB 
05-06 14:38:46.336: D/dalvikvm(29322): GC_FOR_ALLOC freed 139K, 2% free 64841K/65500K, paused 52ms, total 52ms 
05-06 14:38:46.396: I/dalvikvm-heap(29322): Clamp target GC heap from 71.462MB to 64.000MB 
05-06 14:38:46.396: D/dalvikvm(29322): GC_BEFORE_OOM freed <1K, 2% free 64840K/65500K, paused 62ms, total 62ms 

첫째, 그래, 난에 유래와 문제가 무엇인지 알아 내려고 다른 사이트에 파고 많은 일을했습니다. 나는, 비트 맵을 재활용 unbindDrawables를 사용하는 다양한 솔루션을 시도하고 PagerAdapter의() destroyItem에서 비트 맵/뷰를 제거 재활용하려고 ... 몇 가지 이름을했습니다. 이것들 중 어느 것도 나에게 도움이되지 못했다. (필자가 필요하다면 내가 한 일에 대한 자세한 내용을 제공 할 수있다.)

그래서, 간단히 말해서, 나는 (Google 개발자 사이트에서) this example의 수정 된 버전을 사용하여 내 문제를 재현 할 수 있어요. 나는 Universal Image Loader v.1.8.4와 함께 작동하도록 조금 수정하고 또한 내가 일하고 있어요 응용 프로그램이 무엇인지 다소 모방에 좀 더 복잡한 레이아웃을했다. 레이아웃을 변경 한 이유는 레이아웃을 매우 단순하게 만들고 이미지와 일부 텍스트 필드 만 포함하면 모든 것이 잘 작동하는 것처럼 보였기 때문입니다. 레이아웃이 더 복잡 해지면 어댑터에 페이지를 더 추가하기 시작하면 OOM 오류가 발생하기 시작합니다. 그러나, 레이아웃이나 UIL에 문제가 있는지 확실하지 않습니다 ... ...

Eclipse에서 MAT를 실행했으며 여기에 유일한 누출 용의자 보고서 (단 1 문제 만 있음)가 나와 있습니다.) : 당신이 다음 도미네이터 트리를 확인하고 ScreenSlidePagerAdapter를 확장하면

One instance of "com.example.android.animationsdemo.ScreenSlideActivity$ScreenSlidePagerAdapter" 
loaded by "dalvik.system.PathClassLoader @ 0x42124098" occupies 56,171,048 (86.62%) bytes. 
The memory is accumulated in one instance of "java.lang.Object[]" loaded by "<system class loader>". 

Keywords 
java.lang.Object[] 
dalvik.system.PathClassLoader @ 0x42124098 
com.example.android.animationsdemo.ScreenSlideActivity$ScreenSlidePagerAdapter 

, 다음 25 59의 항목을 보여줍니다 :

> java.util.ArrayList @ 0x4216ccf0 
    > java.lang.Object[60] @ 0x44b07d8 
     > android.app.Fragment$SavedState @ 0x439bd038 

이 도구로 어떤 전문가는 아니지만 내가 ' 꽤 안드로이드와 개발에 일반적으로 새롭지 만, 어댑터의 저장된 상태가 아닌 것처럼 보입니다. 올바르게 제거되면 OOM 문제의 원인이됩니다. 비트 맵이 아닌 전체보기가 저장됩니다. 그러나, 나는 내가 다른 곳에서 뭔가를 잘못하고 있어요 경우/해제/파괴/어떤 저장된 상태 데이터를 지우거나하는 방법을 알아낼 수 없었다. 내가 .setSaveEnabled(false)를 사용하여 시도했다 하나 개의 포스트로 실행 않았지만, 그 차이를하지 않았다, 난 여전히 OOM 오류를 얻었다. 나도 어댑터에 대한 saveState() 무시하고 null을 반환 시도하고 그 중 하나를 만들지 않았다.

여기서 잘하면 대부분의 질문에 대답해야 관련 코드/설정 정보의 :

imageLoader.init(ImageLoaderConfiguration.createDefault(this)); 
: 변화는 변화를 보이지 않았기 때문에, 난 그냥 기본 설정을 사용하고 UIL 들어

ScreenSlideActivity :

public class ScreenSlideActivity extends FragmentActivity { 
    /** 
    * The number of pages (wizard steps) to show in this demo. 
    */ 
    private static final String[] IMAGES = Constants.IMAGES; 

    /** 
    * The pager widget, which handles animation and allows swiping horizontally to access previous 
    * and next wizard steps. 
    */ 
    private ViewPager mPager; 

    /** 
    * The pager adapter, which provides the pages to the view pager widget. 
    */ 
    private PagerAdapter mPagerAdapter; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_screen_slide); 

     // Instantiate a ViewPager and a PagerAdapter. 
     mPager = (ViewPager) findViewById(R.id.pager); 
     mPagerAdapter = new ScreenSlidePagerAdapter(getFragmentManager(), IMAGES); 

     mPager.setSaveEnabled(false); // <--- THIS DOESN'T APPEAR TO MAKE ANY DIFFERENCE 

     mPager.setAdapter(mPagerAdapter); 
     mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { 
      @Override 
      public void onPageSelected(int position) { 
       // When changing pages, reset the action bar actions since they are dependent 
       // on which page is currently active. An alternative approach is to have each 
       // fragment expose actions itself (rather than the activity exposing actions), 
       // but for simplicity, the activity provides the actions in this sample. 
       invalidateOptionsMenu(); 
      } 
     }); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     super.onCreateOptionsMenu(menu); 
     getMenuInflater().inflate(R.menu.activity_screen_slide, menu); 

     menu.findItem(R.id.action_previous).setEnabled(mPager.getCurrentItem() > 0); 

     // Add either a "next" or "finish" button to the action bar, depending on which page 
     // is currently selected. 
     MenuItem item = menu.add(Menu.NONE, R.id.action_next, Menu.NONE, 
       (mPager.getCurrentItem() == mPagerAdapter.getCount() - 1) 
         ? R.string.action_finish 
         : R.string.action_next); 
     item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     switch (item.getItemId()) { 
      case android.R.id.home: 
       // Navigate "up" the demo structure to the launchpad activity. 
       // See http://developer.android.com/design/patterns/navigation.html for more. 
       NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class)); 
       return true; 

      case R.id.action_previous: 
       // Go to the previous step in the wizard. If there is no previous step, 
       // setCurrentItem will do nothing. 
       mPager.setCurrentItem(mPager.getCurrentItem() - 1); 
       return true; 

      case R.id.action_next: 
       // Advance to the next step in the wizard. If there is no next step, setCurrentItem 
       // will do nothing. 
       mPager.setCurrentItem(mPager.getCurrentItem() + 1); 
       return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 

    /** 
    * A simple pager adapter that represents 5 {@link ScreenSlidePageFragment} objects, in 
    * sequence. 
    */ 
    private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { 
     String[] mImages; 
     public ScreenSlidePagerAdapter(FragmentManager fm, String[] images) { 
      super(fm); 
      this.mImages = images; 
     } 

     @Override 
     public Fragment getItem(int position) { 
      return ScreenSlidePageFragment.create(position, mImages); 
     } 

     @Override 
     public int getCount() { 
      return IMAGES.length; 
     } 
    } 
} 

ScreenSlidePageFragment, 위의 활동에 의해 호출 :

ViewPager에 대한 ScreenSlideActivity 및 ID로 사용 617,451,515,
public class ScreenSlidePageFragment extends Fragment { 

    // Universal Image Loader 
    private DisplayImageOptions mOptions; 
    protected ImageLoader mImageLoader = ImageLoader.getInstance(); 

    /** 
    * The argument key for the page number this fragment represents. 
    */ 
    public static final String ARG_PAGE = "page"; 

    public static final String ARG_IMAGES = "images"; 

    /** 
    * The fragment's page number, which is set to the argument value for {@link #ARG_PAGE}. 
    */ 
    private int mPageNumber; 
    private String[] mImages; 

    /** 
    * Factory method for this fragment class. Constructs a new fragment for the given page number. 
    */ 
    public static ScreenSlidePageFragment create(int pageNumber, String[] images) { 
     ScreenSlidePageFragment fragment = new ScreenSlidePageFragment(); 
     Bundle args = new Bundle(); 
     args.putInt(ARG_PAGE, pageNumber); 
     args.putStringArray(ARG_IMAGES, images); 
     fragment.setArguments(args); 
     return fragment; 
    } 

    public ScreenSlidePageFragment() { 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     mPageNumber = getArguments().getInt(ARG_PAGE); 
     mImages = getArguments().getStringArray(ARG_IMAGES); 

     mOptions = new DisplayImageOptions.Builder() 
     .showImageForEmptyUri(R.drawable.ic_empty) 
     .showImageOnFail(R.drawable.ic_error) 
     .resetViewBeforeLoading() 
     .cacheOnDisc() 
     .imageScaleType(ImageScaleType.EXACTLY) 
     .bitmapConfig(Bitmap.Config.RGB_565) 
     .displayer(new SimpleBitmapDisplayer()) 
     .build(); 

    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     // Inflate the layout containing a title and body text. 
     ViewGroup rootView = (ViewGroup) inflater 
       .inflate(R.layout.fragment_screen_slide_page, container, false); 

     // Set the title view to show the page number. 
     ((TextView) rootView.findViewById(android.R.id.text1)).setText(
       getString(R.string.title_template_step, mPageNumber + 1)); 
     displayImageFile(rootView); 
     return rootView; 
    } 

    private void displayImageFile (ViewGroup view) { 

     ImageView imageView = (ImageView) view.findViewById(R.id.item_image_to_display); 

     mImageLoader.displayImage(mImages[mPageNumber], imageView, mOptions); 

    } 

    /** 
    * Returns the page number represented by this fragment object. 
    */ 
    public int getPageNumber() { 
     return mPageNumber; 
    } 
} 

레이아웃 activity_screen_slide.xml :

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/pager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

fragment_screen_slide_page.ScreenSlidePageFragment에서 사용하는 XML :

05-06 16:37:59.656: E/ImageLoader(3175): null 
05-06 16:37:59.656: E/ImageLoader(3175): java.lang.OutOfMemoryError 
05-06 16:37:59.656: E/ImageLoader(3175): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 
05-06 16:37:59.656: E/ImageLoader(3175): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:529) 
05-06 16:37:59.656: E/ImageLoader(3175): at com.nostra13.universalimageloader.core.ImageDecoder.decode(ImageDecoder.java:82) 
05-06 16:37:59.656: E/ImageLoader(3175): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.decodeImage(LoadAndDisplayImageTask.java:270) 
05-06 16:37:59.656: E/ImageLoader(3175): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:224) 
05-06 16:37:59.656: E/ImageLoader(3175): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:149) 
05-06 16:37:59.656: E/ImageLoader(3175): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
05-06 16:37:59.656: E/ImageLoader(3175): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
05-06 16:37:59.656: E/ImageLoader(3175): at java.lang.Thread.run(Thread.java:856) 

나는 순서/변경에서 무엇을 볼 수는 OOM 오류를 제거하는 :

또한
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <!-- Dummy content. --> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:padding="16dp" > 

     <TextView 
      android:id="@android:id/text1" 
      style="?android:textAppearanceLarge" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="16dp" 
      android:textStyle="bold" /> 

     <TextView 
      style="?android:textAppearanceMedium" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:lineSpacingMultiplier="1.2" 
      android:text="@string/lorem_ipsum" /> 

     <TextView 
      android:id="@+id/item_details" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:gravity="center_vertical" 
      android:text="@string/item_details" /> 

     <TextView 
      android:id="@+id/item_type_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:text="@string/item_type_text" /> 

     <Spinner 
      android:id="@+id/item_type" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:prompt="@string/item_type_text" 
      android:text="@string/item_type" /> 

     <TextView 
      android:id="@+id/item_name_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:text="@string/item_name_text" /> 

     <EditText 
      android:id="@+id/item_name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:gravity="top|left" 
      android:hint="@string/item_name" 
      android:inputType="text" /> 

     <TextView 
      android:id="@+id/item_text_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:text="@string/item_text_text" /> 

     <EditText 
      android:id="@+id/item_text" 
      android:layout_width="wrap_content" 
      android:layout_height="100dp" 
      android:layout_marginLeft="10dp" 
      android:ems="10" 
      android:gravity="top|left" 
      android:hint="@string/item_text" 
      android:inputType="textMultiLine" /> 

     <TextView 
      android:id="@+id/sound_edit_text" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:gravity="center_vertical" 
      android:text="@string/sound_edit" /> 

     <ImageView 
      android:id="@+id/item_add_audio" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="10dp" 
      android:contentDescription="@string/cd_image_add_button" 
      android:src="@android:drawable/ic_menu_add" /> 

     <TextView 
      android:id="@+id/recording_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginBottom="20dp" 
      android:layout_marginTop="20dp" 
      android:text="@string/recording_text" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:padding="16dp" > 

      <ImageButton 
       android:id="@+id/item_play_audio" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="33" 
       android:contentDescription="@string/cd_play_sound_button" 
       android:soundEffectsEnabled="false" 
       android:src="@drawable/play" /> 

      <ImageButton 
       android:id="@+id/item_stop_audio" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="34" 
       android:contentDescription="@string/cd_stop_sound_button" 
       android:soundEffectsEnabled="false" 
       android:src="@drawable/stop" /> 

      <ImageButton 
       android:id="@+id/item_record_audio" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="33" 
       android:contentDescription="@string/cd_record_sound_button" 
       android:soundEffectsEnabled="false" 
       android:src="@drawable/rec" /> 
     </LinearLayout> 

     <TextView 
      android:id="@+id/edit_image" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:gravity="center_vertical" 
      android:text="@string/edit_image" /> 

     <TextView 
      android:id="@+id/image_replace_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginBottom="10dp" 
      android:layout_marginTop="10dp" 
      android:text="@string/image_replace" 
      android:visibility="visible" /> 

     <ImageView 
      android:id="@+id/item_image_to_display" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:adjustViewBounds="true" 
      android:contentDescription="@string/cd_item_image" /> 

     <TextView 
      android:id="@+id/item_image_effect_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:text="@string/item_image_effect_text" /> 

     <Spinner 
      android:id="@+id/item_image_effect" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" /> 

     <TextView 
      android:id="@+id/item_text_color_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:text="@string/item_text_color_text" /> 

     <Spinner 
      android:id="@+id/item_text_color" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" /> 

     <TextView 
      android:id="@+id/item_text_size_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:text="@string/item_text_size_text" /> 

     <EditText 
      android:id="@+id/item_text_size" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:hint="@string/item_text_size" 
      android:inputType="number" /> 

     <TextView 
      android:id="@+id/item_text_style_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:text="@string/item_text_style_text" /> 

     <Spinner 
      android:id="@+id/item_text_style" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" /> 

     <TextView 
      android:id="@+id/item_text_alignment_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:text="@string/item_text_alignment_text" /> 

     <Spinner 
      android:id="@+id/item_text_alignment" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" /> 

     <TextView 
      android:id="@+id/item_background_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:text="@string/item_background_text" /> 

     <Spinner 
      android:id="@+id/item_background" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" /> 
    </LinearLayout> 

</ScrollView> 

, 나는 여기에 실행 OOM 오류가있어?

답변

4

내 문제를 해결하는 unbindDrawables가 나타났습니다. 내가 전에 잘못하고 있었던 것을 확신하지 못했다. (너무 늦었다 ... ??? ;-)). 그러나 나는 this post을 만났고, 내 문제를 해결했다. 앞서 언급 한 게시물은 내가 본 다른 unbindDrawable 게시물 중 일부와 조금 다른데 다른 버전을 시도했을 때처럼 java.lang.UnsupportedOperationException: removeAllViews() is not supported in AdapterView 오류가 발생하지 않았습니다. (내 부분에 뭔가 어리 석었을 수 있습니다).

나는하여 ScreenSildePageFragment 클래스에 다음과 같은 구현 내 OOM 문제 해결 :

@Override 
protected void onDestroy() 
{ 
     super.onDestroy(); 

     unbindDrawables(mRootView.findViewById(R.id.content)); // <---This should be the ID of this fragments (ScreenSlidePageFragment) layout 
} 

private void unbindDrawables(View view) 
{ 
     if (view.getBackground() != null) 
     { 
       view.getBackground().setCallback(null); 
     } 
     if (view instanceof ViewGroup && !(view instanceof AdapterView)) 
     { 
       for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) 
       { 
         unbindDrawables(((ViewGroup) view).getChildAt(i)); 
       } 
       ((ViewGroup) view).removeAllViews(); 
     } 
} 

참고 : 나는 (들의 OnDestroy()에서 unbindDrawables를 호출 한 후 System.gc();을 사용하지 않은) 포스트에서 언급 한 바와 같이합니다. 그것을 사용하여 테스트 한 장치에 어떤 실질적인 차이를 만드는 것 같지 않았고 시스템에서 가비지 수집을 관리하게하는 것이 더 좋을 것이라고 생각했습니다.

+0

마지막으로, 비슷한 해결책을 찾고 있습니다. 건배 –

+0

내 경우에 unbindDrawables() 메서드가 Null 포인터 예외를주는 이유는 무엇입니까? –

+0

@SalmanKhan, 아마도 null보기를 전달하기 때문일 수 있습니다. 모든보기/변수가 올바르게 설정되었는지 확인하십시오. 코드 예제가 없다면 아무도 정말로 당신을 도울 수 없습니다. 이 경우 도움을 얻기 위해 코드를 질문으로 게시하는 것이 가장 좋습니다. – Jason

0

비슷한 문제가 발생했습니다. getFragmentManager() 대신 getChildFragmentManager()으로 어댑터를 인스턴스화하면 내 문제가 해결됩니다.