Results 1 to 2 of 2

Thread: Java heap space

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Qt products
    Qt3
    Platforms
    Windows
    Thanks
    53

    Default Java heap space

    Hello,
    i write a program that creates many hashTable; it counts the frequency of each word in some document s(that it's very large). So there are many words... This is a part of code. Do you know how come overcome this problem (in general) ?

    thanks
    Qt Code:
    1. ..............................
    2. HashMap<String, Double> frequency = null;
    3. for (every document ) {
    4. frequency = new HashMap<String, Double>();
    5. //select a word and count
    6. frequecny.put( myWord , new Integer (count ) );
    7. }
    8. .................................................................
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    2. at java.util.HashMap.resize(Unknown Source)
    3. at java.util.HashMap.addEntry(Unknown Source)
    4. at java.util.HashMap.put(Unknown Source)
    5. at MyClass.setting(MyClass.java:71)
    6. at filter.main(filter.java:19)
    To copy to clipboard, switch view to plain text mode 
    Last edited by mickey; 15th December 2008 at 19:15.
    Regards

  2. #2
    Join Date
    Jan 2006
    Posts
    976
    Qt products
    Qt3
    Platforms
    Windows
    Thanks
    53

    Default Re: Java heap space

    I notice only now that the real problem seem to be here:
    Qt Code:
    1. public String read(String filesDir, String file){
    2.  
    3. StringBuilder fileData = new StringBuilder(1000);
    4. try {
    5. BufferedReader reader = new BufferedReader( new FileReader( new File(filesDir + "//" + file) ));
    6. try {
    7. char[] buf = new char[1024];
    8. int numRead = 0;
    9. while((numRead=reader.read(buf)) != -1){
    10. fileData.append(buf, 0, numRead);
    11. }
    12. } finally { reader.close(); }
    13.  
    14. } catch (IOException e) {
    15. System.out.println("file not found");
    16. System.exit(-1);
    17.  
    18. }
    19.  
    20.  
    21. return fileData.toString();
    To copy to clipboard, switch view to plain text mode 
    on the "fileData.append(buf, 0, numRead);"
    I've made a mistake: i have 2500 files to read.....
    any suggestions?
    Regards

Similar Threads

  1. linking user space and kernel space programs with qmake
    By zielchri in forum Qt Programming
    Replies: 9
    Last Post: 8th March 2006, 23:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.