我遇到了我的应用程序用例,需要在其中插入约1000条记录。我的应用程序现在正在OOM中运行。
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract fun insertAll(items: List<ItemEntity>)
我尝试过:
bookEntityList.asSequence().chunked(50).forEach {
bookDao.insertAll(it)
}
但这也不起作用。制作这么大的刀片的最佳方法是什么?
这是我看到的日志:
2020-06-04 14:27:44.161 Background concurrent copying GC freed 4588(320KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 231us total 446.242ms
2020-06-04 14:27:44.161 WaitForGcToComplete blocked Alloc on HeapTrim for 445.238ms
2020-06-04 14:27:44.161 Starting a blocking GC Alloc
2020-06-04 14:27:44.162 WaitForGcToComplete blocked Alloc on HeapTrim for 443.251ms
2020-06-04 14:27:44.162 Starting a blocking GC Alloc
2020-06-04 14:27:44.162 WaitForGcToComplete blocked Alloc on HeapTrim for 14.494ms
2020-06-04 14:27:44.162 Starting a blocking GC Alloc
2020-06-04 14:27:44.190 Waiting for a blocking GC Alloc
2020-06-04 14:27:44.190 Waiting for a blocking GC Alloc
Stacktrace:
java.lang.OutOfMemoryError: Failed to allocate a 1496 byte allocation with 328 free bytes and 328B until OOM, max allowed footprint 100663296, growth limit 100663296
at android.icu.impl.ICUBinary.getShorts(ICUBinary.java:673)
at android.icu.text.RBBIDataWrapper.get(RBBIDataWrapper.java:248)
at android.icu.text.RuleBasedBreakIterator.getInstanceFromCompiledRules(RuleBasedBreakIterator.java:95)
at android.icu.text.BreakIteratorFactory.createBreakInstance(BreakIteratorFactory.java:155)
at android.icu.text.BreakIteratorFactory.createBreakIterator(BreakIteratorFactory.java:73)
at android.icu.text.BreakIterator.getBreakInstance(BreakIterator.java:836)
at android.icu.text.BreakIterator.getWordInstance(BreakIterator.java:565)
at java.text.BreakIterator.getWordInstance(BreakIterator.java:457)
at android.view.textclassifier.SelectionSessionLogger.getTokenIterator(SelectionSessionLogger.java:234)
at android.widget.SelectionActionModeHelper$SelectionMetricsLogger.<init>(SelectionActionModeHelper.java:688)
at android.widget.SelectionActionModeHelper$SelectionTracker.<init>(SelectionActionModeHelper.java:498)
at android.widget.SelectionActionModeHelper.<init>(SelectionActionModeHelper.java:92)
at android.widget.Editor.getSelectionActionModeHelper(Editor.java:2161)
at android.widget.Editor.sendOnTextChanged(Editor.java:1358)
at android.widget.TextView.sendOnTextChanged(TextView.java:9800)
at android.widget.TextView.setText(TextView.java:5760)
at android.widget.TextView.setText(TextView.java:5598)
at android.widget.EditText.setText(EditText.java:122)
at android.widget.TextView.setText(TextView.java:5555)
at android.widget.TextView.setTransformationMethod(TextView.java:2441)
at android.widget.TextView.applySingleLine(TextView.java:9493)
at android.widget.TextView.<init>(TextView.java:1460)
at android.widget.EditText.<init>(EditText.java:88)
at android.widget.EditText.<init>(EditText.java:84)
at androidx.appcompat.widget.AppCompatEditText.<init>(AppCompatEditText.java:69)
at androidx.appcompat.widget.AppCompatEditText.<init>(AppCompatEditText.java:65)
at androidx.appcompat.app.AppCompatViewInflater.createEditText(AppCompatViewInflater.java:192)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:114)
at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)