public void cleanupMatrixObject(MatrixObject mo) throws DMLRuntimeException {
   try {
     if (mo.isCleanupEnabled()) {
       // compute ref count only if matrix cleanup actually necessary
       if (!getVariables().hasReferences(mo)) {
         // clean cached data
         mo.clearData();
         if (mo.isHDFSFileExists()) {
           // clean hdfs data
           String fpath = mo.getFileName();
           if (fpath != null) {
             MapReduceTool.deleteFileIfExistOnHDFS(fpath);
             MapReduceTool.deleteFileIfExistOnHDFS(fpath + ".mtd");
           }
         }
       }
     }
   } catch (Exception ex) {
     throw new DMLRuntimeException(ex);
   }
 }