2012-03-22 6 views
1

私は例外次のようになっています:folowingコードでjava.lang.OutOfMemoryErrorを:[メモリ使い果たさ]

03-22 23:34:23.775: E/dalvikvm-heap(563): Out of memory on a 216-byte allocation. 
    03-22 23:34:23.775: I/dalvikvm(563): "main" prio=5 tid=1 RUNNABLE 
    03-22 23:34:23.775: I/dalvikvm(563): | group="main" sCount=0 dsCount=0 obj=0x409c1460 self=0x12810 
    03-22 23:34:23.775: I/dalvikvm(563): | sysTid=563 nice=0 sched=0/0 cgrp=default handle=1074082952 
    03-22 23:34:23.775: I/dalvikvm(563): | schedstat=(185232190544 11744128421 6399) utm=18163 stm=360 core=0 
    03-22 23:34:23.775: I/dalvikvm(563): at java.lang.Throwable.nativeFillInStackTrace(Native Method) 
    03-22 23:34:23.775: I/dalvikvm(563): at java.lang.Throwable.fillInStackTrace(Throwable.java:160) 
    03-22 23:34:23.775: I/dalvikvm(563): at java.lang.Throwable.<init>(Throwable.java:83) 
    03-22 23:34:23.775: I/dalvikvm(563): at java.lang.Error.<init>(Error.java:37) 
    03-22 23:34:23.775: I/dalvikvm(563): at java.lang.VirtualMachineError.<init>(VirtualMachineError.java:35) 
    03-22 23:34:23.775: I/dalvikvm(563): at java.lang.OutOfMemoryError.<init>(OutOfMemoryError.java:33) 
    03-22 23:34:23.785: I/dalvikvm(563): at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:-1) 
    03-22 23:34:23.785: I/dalvikvm(563): at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:145) 
    03-22 23:34:23.785: I/dalvikvm(563): at java.lang.StringBuffer.append(StringBuffer.java:219) 
    03-22 23:34:23.785: I/dalvikvm(563): at com.swabunga.spell.engine.DoubleMeta.transform((null):-1) 
    03-22 23:34:23.785: I/dalvikvm(563): at com.swabunga.spell.engine.SpellDictionaryASpell.getCode((null):-1) 
    03-22 23:34:23.785: I/dalvikvm(563): at com.swabunga.spell.engine.SpellDictionaryHashMap.putWord((null):-1) 
    03-22 23:34:23.785: I/dalvikvm(563): at com.swabunga.spell.engine.SpellDictionaryHashMap.createDictionary((null):-1) 
    03-22 23:34:23.785: I/dalvikvm(563): at com.swabunga.spell.engine.SpellDictionaryHashMap.<init>((null):-1) 
    03-22 23:34:23.785: I/dalvikvm(563): at com.spellchecker.SpellCheckerService.<init>(SpellCheckerService.java:49) 
    03-22 23:34:23.785: I/dalvikvm(563): at com.dict.SearchDict.handleIntent(SearchDict.java:150) 
    03-22 23:34:23.785: I/dalvikvm(563): at com.dict.SearchDict.onNewIntent(SearchDict.java:87) 
    03-22 23:34:23.785: I/dalvikvm(563): at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1123) 
    03-22 23:34:23.785: I/dalvikvm(563): at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:2042) 
    03-22 23:34:23.785: I/dalvikvm(563): at android.app.ActivityThread.performNewIntents(ActivityThread.java:2055) 
    03-22 23:34:23.785: I/dalvikvm(563): at android.app.ActivityThread.handleNewIntent(ActivityThread.java:2064) 
    03-22 23:34:23.785: I/dalvikvm(563): at android.app.ActivityThread.access$1400(ActivityThread.java:123) 
    03-22 23:34:23.785: I/dalvikvm(563): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1194) 
    03-22 23:34:23.795: I/dalvikvm(563): at android.os.Handler.dispatchMessage(Handler.java:99) 
    03-22 23:34:23.795: I/dalvikvm(563): at android.os.Looper.loop(Looper.java:137) 
    03-22 23:34:23.795: I/dalvikvm(563): at android.app.ActivityThread.main(ActivityThread.java:4424) 
    03-22 23:34:23.795: I/dalvikvm(563): at java.lang.reflect.Method.invokeNative(Native Method) 
    03-22 23:34:23.795: I/dalvikvm(563): at java.lang.reflect.Method.invoke(Method.java:511) 
    03-22 23:34:23.795: I/dalvikvm(563): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
    03-22 23:34:23.795: I/dalvikvm(563): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
    03-22 23:34:23.795: I/dalvikvm(563): at dalvik.system.NativeStart.main(Native Method) 
     java.lang.OutOfMemoryError: [memory exhausted] 
     at dalvik.system.NativeStart.main(Native Method) 

 File wordList=new File(Environment.getExternalStorageDirectory() + File.separator + "wordlist.0"); 
     if(!wordList.exists()) 
     { 
      wordList.createNewFile(); 
      BufferedReader reader = new BufferedReader(new InputStreamReader(SearchDict.context.getResources().openRawResource(R.raw.wordlist))); 
      BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(wordList))); 
      String line;     
      while ((line = reader.readLine()) != null) 
      { 
       writer.write(line); 
       writer.newLine(); 
      } 
     } 
     SpellDictionaryHashMap spelldictionaryhashmap = new SpellDictionaryHashMap(wordList, null); 
     spellCheck = new SpellChecker(spelldictionaryhashmap); 
     spellCheck.addSpellCheckListener(this); 
     spellCheck.checkSpelling(new StringWordTokenizer(s)); 

私はスペルチェッカーを実装している辞書を開発していますJAZZY APIを使用します。上記のコードは、通常、生のフォルダの単語リストから単語を読み取り、ファイルに書き込むその一部です。単語リストのハッシュコードを作成するには、単語リストをjava.io.Fileとしてcom.swabunga.spell.engine.SpellDictionaryHashMapに渡す必要があるためです。

このプロセスが進行している間、この例外はスローされました。

+2

あなたの質問はまったく何ですか? – ChrisWue

答えて

3

このコードはどのくらいの頻度で実行されますか?そこには多くの割り当てが行われています。これはあなたが本当に可能な限りこれらのオブジェクトの多くを引き出し、あなたがそれらを再利用することができますので周囲にそれらを維持する方法を見つける必要があります複数回呼び出された場合

new File 
new BufferedReader 
new InputStreamReader 
new BufferedWriter 
new OutputStreamWriter 
new SpellDictionaryHashMap 
new SpellChecker 
new StringWordTokenizer 

+0

まあ、私は生のフォルダのテキストファイルの内容を外部ストレージのファイルにコピーするのに使用した以外の方法はありません。私はそれをSpellDictionaryHashMapに渡すことができます。 –

+0

また、あなたのポイントを教えてください。私の意見では、割り当ては一度だけ行われます。 –

+0

それは私が求めていたものです。それは何回行われましたか?何の文脈もなければ、あなたはそれを一度呼び出すのか、それとも何百回もそれを呼んでいたのか分かりませんでした。 – CaseyB

0

非常に大きな辞書を読み込もうとしていると思われます。例外として、メモリが不足していると考えられます。このような場合は、SpellDictionaryHashMapを使用しないでください。代わりに、辞書全体をメモリに読み込まず、ディスクから読み込む異なる実装を使用する必要があります。

+0

あなたはどんなアイデアを持っていますか? –

+1

あなたは 'SpellDictionaryDisk'または' SpellDictionaryDichoDisk'を試しましたか? – kabuko

+0

私はSpellDictionaryDiskを使ってみましたが、java.io.FileNotFoundExceptionが発生しました:必要なパス '/mnt/sdcard/wordlist.0/words'を見つけることができませんでした 例外。私が行った唯一の変更は、私がSpellDictionaryHashMapを除外したことです。私はパスを変更していないが、私にパスエラーを与える方法はありません。 –

関連する問題