1

I am getting following exception:

    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)

in the folowing code:

        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));

I am developing a dictionary in which I have implemented spell checker using JAZZY API. The above code is a part of it which typically reads the words from the word list in raw folder and writes to the file. Because I need to pass the word list as java.io.File to the com.swabunga.spell.engine.SpellDictionaryHashMap for creation of hash code of the word list.

While the process was going on this exception got thrown.

1
  • 2
    And your question is exactly what? Commented Mar 22, 2012 at 18:36

2 Answers 2

3

How often is that chunk of code run? There is a lot of allocation going on there.

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

If this is called more than once you really should find a way to pull out as many of these object as possible and keep them around so you can reuse them.

Sign up to request clarification or add additional context in comments.

3 Comments

Well, is there any other way than the one I have used to copy the contents of text file in the raw folder to a file in the external storage. So that I can pass it to SpellDictionaryHashMap.
And also could you explain me your point. In my opinion the allocation is done only once.
That's what I was asking. How many times was it done. Without any context I didn't know if you were calling it once or if you were calling it hundreds of times.
0

I suspect you're trying to load a very large dictionary and as the exception suggests are simply running out of memory. If this is the case, you should not be using SpellDictionaryHashMap. Instead should use a different implementation that doesn't load the entire dictionary into memory but reads from disk.

7 Comments

Have you tried SpellDictionaryDisk or SpellDictionaryDichoDisk...?
I tried using SpellDictionaryDisk but I am getting java.io.FileNotFoundException: Couldn't find required path '/mnt/sdcard/wordlist.0/words' exception. The only changes I have made is that I have excluded SpellDictionaryHashMap. I don't then how come it is giving me the path error though I have not changed the path.
You need to read the documentation of the classes that you use.
I am fed up and I am not progressing at all. Though I am not getting FileNotFoundException but now I am getting NullPointerException though I have pushed the file in the emulator device using DDMS. I checked documentation but of no use for my problem. Problem was that the path was wrong. What actually happens is that SpellDictionaryDisk checks in the "words" folder in the base path specified. For eg. if I specify a base path of /mnt/sdcard then SpellDictionaryDisk will look in /mnt/sdcard/words directory for the files. I said ok and formatted the path to /mnt/sdcard and placed my file in
/mnt/sdcard/words. So now the SpellDictionaryDisk does not gives me FileNotFoundException but NullPointerException. But after the exception I guess the word gets to store in memory because logcat starts to give me log messages like "GC_CONCURRENT freed 149K, 3% free 10407K/10631K, paused 5ms+16ms GC_CONCURRENT freed 68K, 2% free 10871K/11015K, paused 4ms+13ms GC_CONCURRENT freed 33K, 1% free 11482K/11591K, paused 4ms+12ms GC_CONCURRENT freed 117K, 2% free 12230K/12423K, paused 4ms+18ms " which shows that words are being stored in memory for spell checking purpose. But again OutOfMemoryError.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.