'How to handle "Background concurrent copying GC freed" to keep or increase the app performance?

During testing an android app on a real device, I need to list the remote directory contents on a ftp server recursive with the method below via FtpClient from the Apache Commons Net 3.8.0 library. When there are a lot of (sub)files and (sub)folders inside the directory, many log messages appears that contains "Background concurrent copying GC freed AllocSpace objects". This results in bad app performance and UI responses are slow. The method is called from a background thread of course. So the question is, how can I fix this beavior?

Background concurrent copying GC freed 3588(4192KB) AllocSpace objects, 2216(108MB) LOS objects, 46% free, 54MB/102MB, paused 238us total 105.088ms Background concurrent copying GC freed 3544(4192KB) AllocSpace objects, 2171(102MB) LOS objects, 46% free, 55MB/103MB, paused 238us total 100.097ms Background concurrent copying GC freed 3428(4160KB) AllocSpace objects, 2072(106MB) LOS objects, 44% free, 59MB/107MB, paused 236us total 102.145ms

void listDirectory(FTPClient ftpClient, String parentDir,
                   String currentDir ) throws IOException {

    String dirToList = parentDir;
    if (!currentDir.equals("")) {
        dirToList += "/" + currentDir;
    }

    FTPFile[] subFiles = ftpClient.listFiles(dirToList);
    if (subFiles != null && subFiles.length > 0) {
        for (FTPFile aFile : subFiles) {
            String currentFileName = aFile.getName();
            if (currentFileName.equals(".")
                    || currentFileName.equals("..")) {
                continue;
            }

            if (aFile.isDirectory()) {
                Log.i(TAG,"Folder: " + currentFileName);
                listDirectory(ftpClient, dirToList, currentFileName);

            }else {
                Log.i(TAG,"File: " + currentFileName);
            }
        }
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source