Jawad Amjad
Jawad Amjad

Reputation: 2552

A new error I never seen before in Android. Is there any Solution?

02-07 10:49:45.558: E/dalvikvm-gc(7184): Could not create 2617344-byte ashmem mark stack: Too many open files

While I was playing the game and after some time the game forced closed showing the above error in Log Cat. Is there any solution for this?? and what could be its cause??

Upvotes: 0

Views: 480

Answers (1)

Ted Hopp
Ted Hopp

Reputation: 234795

The cause is that your code is not closing files and the system is running out of file handles. You should always use files using a coding pattern that ensures that all streams are closed when no longer needed. Here's a typical pattern:

InputStream is = null;
try {
    is = new FileInputStream(myFile);
    // read stuff from is
} finally {
    if (is != null) {
        try {
            is.close();
        } catch (IOException e) {
            Log.w(LOG_TAG, "Exception raised when closing file", e);
        }
    }
}

The outer try could also have a catch clause. The reason for the try/catch in the finally clause is to prevent an exception in closing the file from suppressing any exception raised in the outer try block.

Writing to files tends to be less of a problem because programmers usually take care to close the file to ensure that the data reaches the file. However, a similar pattern should be followed there: never let an exception prevent the closing of a file.

Upvotes: 2

Related Questions