diff --git a/ItemInfo.pde b/ItemInfo.pde index f352e5a..7254eeb 100644 --- a/ItemInfo.pde +++ b/ItemInfo.pde @@ -92,7 +92,7 @@ class ItemInfo } public boolean initialiseItemInfo() - { + { // Now open the relevant I* file - use the version which has been downloaded/copied to OrigJSONs // If it is not there then report an error String itemFileName = workingDir + File.separatorChar + "OrigJSONs" + File.separatorChar+ itemTSID + ".json"; @@ -182,7 +182,6 @@ class ItemInfo // Initialise for the item to be searched for //itemImageBeingUsed = 0; - if (!resetReadyForNewItemSearch()) { return false; @@ -1193,6 +1192,12 @@ class ItemInfo return true; } + public void clearFragFind() + { + fragFind = null; + System.gc(); + } + public boolean resetAsMissingQuoin() { // This function is called if it is a quoin found to have the same x,y as another quoin diff --git a/Memory.pde b/Memory.pde index 720d26c..e9267cd 100644 --- a/Memory.pde +++ b/Memory.pde @@ -16,4 +16,15 @@ public class Memory { //" Used Memory: " + (instance.totalMemory() - instance.freeMemory()) + " Max Memory: " + instance.maxMemory() / mb + (instance.totalMemory() - instance.freeMemory()) / mb, 1); } + + public void printUsedMemory(String info) + { + int mb = 1024 * 1024; + + // get Runtime instance + Runtime instance = Runtime.getRuntime(); + // Insert a comma - then allows these output lines to be put into a spreadsheet so can graph memory usage + printToFile.printDebugLine(this, "\"" + info + "\"," + (instance.totalMemory() - instance.freeMemory()) / mb, 1); + + } } \ No newline at end of file diff --git a/PNGFile.pde b/PNGFile.pde index 7233547..980112f 100644 --- a/PNGFile.pde +++ b/PNGFile.pde @@ -89,12 +89,14 @@ class PNGFile public boolean loadPNGImage() { + memory.printUsedMemory("image load start " + PNGImageName); // Load up this snap/item image String fullFileName; if (PNGImage != null) { // Image has already been loaded into memory + memory.printUsedMemory("image load end (already loaded) " + PNGImageName); return true; } @@ -128,6 +130,7 @@ class PNGFile try { // load image pixels + memory.printUsedMemory("image load pre-loadPixels " + PNGImageName); PNGImage.loadPixels(); } catch(Exception e) @@ -138,16 +141,25 @@ class PNGFile } printToFile.printDebugLine(this, "Loading image from " + fullFileName + " with width " + PNGImage.height + " height " + PNGImage.width, 1); - + memory.printUsedMemory("image load end " + PNGImageName); return true; } public void unloadPNGImage() - { + { + memory.printUsedMemory("image unload start " + PNGImageName); + if (PNGImage == null) + { + printToFile.printDebugLine(this, "!!!! Unloading null image " + PNGImageName, 3); + } + // workaround to remove memory leak - https://github.com/processing/processing/issues/1391.html#issuecomment-13356835 + g.removeCache(PNGImage); + PNGImage = null; printToFile.printDebugLine(this, "Unloading image " + PNGImageName, 1); // Need this to force the garbage collection to free up the memory associated with the image System.gc(); + memory.printUsedMemory("image unload end " + PNGImageName); } } \ No newline at end of file diff --git a/PrintToFile.pde b/PrintToFile.pde index d5de25c..1a9db3e 100644 --- a/PrintToFile.pde +++ b/PrintToFile.pde @@ -361,7 +361,7 @@ class PrintToFile { if (itemResults.get(i).itemInfo.readItemClassTSID().equals("quoin")) { s = s + "MISSING quoin " + itemResults.get(i).itemInfo.readItemTSID() + ": " + itemResults.get(i).itemInfo.readItemClassTSID(); - s = s + "(" + itemResults.get(i).itemInfo.readOrigItemVariant() + "/" + itemResults.get(i).itemInfo.readOrigItemClassName() + ")"; + s = s + "(" + itemResults.get(i).itemInfo.readOrigItemClassName() + ")"; s = s + " defaulted to (mystery/placement tester)"; } else @@ -376,7 +376,7 @@ class PrintToFile { s = s + "Changed co-ords " + itemResults.get(i).itemInfo.readItemTSID() + ": " + itemResults.get(i).itemInfo.readItemClassTSID(); if (itemResults.get(i).itemInfo.readItemClassTSID().equals("quoin")) { - s = s + "(" + itemResults.get(i).itemInfo.readOrigItemVariant() + "/" + itemResults.get(i).itemInfo.readOrigItemClassName() + ")"; + s = s + "(" + itemResults.get(i).itemInfo.readOrigItemClassName() + ")"; } else { @@ -388,8 +388,8 @@ class PrintToFile { s = s + "Changed variant " + itemResults.get(i).itemInfo.readItemTSID() + ": " + itemResults.get(i).itemInfo.readItemClassTSID(); if (itemResults.get(i).itemInfo.readItemClassTSID().equals("quoin")) { - s = s + "(" + itemResults.get(i).itemInfo.readNewItemVariant() + "/" + itemResults.get(i).itemInfo.readNewItemClassName() + ")"; - s = s + " (was " + itemResults.get(i).itemInfo.readOrigItemVariant() + "/" + itemResults.get(i).itemInfo.readOrigItemClassName() + ")"; + s = s + "(" + itemResults.get(i).itemInfo.readNewItemClassName() + ")"; + s = s + " (was " + itemResults.get(i).itemInfo.readOrigItemClassName() + ")"; } else { @@ -409,8 +409,8 @@ class PrintToFile { s = s + "Changed variant & co-ords " + itemResults.get(i).itemInfo.readItemTSID() + ": " + itemResults.get(i).itemInfo.readItemClassTSID(); if (itemResults.get(i).itemInfo.readItemClassTSID().equals("quoin")) { - s = s + "(" + itemResults.get(i).itemInfo.readNewItemVariant() + "/" + itemResults.get(i).itemInfo.readNewItemClassName() + ")"; - s = s + " (was " + itemResults.get(i).itemInfo.readOrigItemVariant() + "/" + itemResults.get(i).itemInfo.readOrigItemClassName() + ")"; + s = s + "(" + itemResults.get(i).itemInfo.readNewItemClassName() + ")"; + s = s + " (was " + itemResults.get(i).itemInfo.readOrigItemClassName() + ")"; } else { @@ -427,22 +427,12 @@ class PrintToFile { break; case SummaryChanges.UNCHANGED: - /* - if (itemResults.get(i).readAlreadySetDirField()) - { - // This handles the case of e.g. shrine where x,y unchanged and just inserted the missing dir field - // Had to fake up the missing variant field in order to correctly handle images - s = s + "Changed variant "; - s = s + itemResults.get(i).itemInfo.readItemTSID() + ": " + itemResults.get(i).itemInfo.readItemClassTSID(); - } - else - {*/ - s = s + "Unchanged "; - s = s + itemResults.get(i).itemInfo.readItemTSID() + ": " + itemResults.get(i).itemInfo.readItemClassTSID(); - //} + s = s + "Unchanged "; + s = s + itemResults.get(i).itemInfo.readItemTSID() + ": " + itemResults.get(i).itemInfo.readItemClassTSID(); + if (itemResults.get(i).itemInfo.readItemClassTSID().equals("quoin")) { - s = s + "(" + itemResults.get(i).itemInfo.readOrigItemVariant() + "/" + itemResults.get(i).itemInfo.readOrigItemClassName() + ")"; + s = s + "(" + itemResults.get(i).itemInfo.readOrigItemClassName() + ")"; } else { diff --git a/StreetInfo.pde b/StreetInfo.pde index 3b2dda4..5167926 100644 --- a/StreetInfo.pde +++ b/StreetInfo.pde @@ -763,8 +763,13 @@ class StreetInfo { // Item needs to be skipped/or has already been found // Move onto next one - printToFile.printDebugLine(this, "Skipping item " + itemInfo.get(itemBeingProcessed).readItemClassTSID() + "(" + - itemInfo.get(itemBeingProcessed).readOrigItemVariant() + ") " + itemInfo.get(itemBeingProcessed).readItemTSID(), 1); + String s = "Skipping item " + itemInfo.get(itemBeingProcessed).readItemClassTSID(); + if (itemInfo.get(itemBeingProcessed).readOrigItemVariant().length() > 0) + { + s = s + " (" + itemInfo.get(itemBeingProcessed).readOrigItemVariant() + ")"; + } + s = s + " " + itemInfo.get(itemBeingProcessed).readItemTSID(); + printToFile.printDebugLine(this, s, 1); // As we just want to pass control back up, don't care about the succes/failure - top level will handle that if (moveToNextItem()) @@ -780,7 +785,6 @@ class StreetInfo //ItemInfo itemData = itemInfo.get(itemBeingProcessed); // Display information - //displayMgr.setStreetName(streetName, streetTSID, streetBeingProcessed + 1, configInfo.readTotalJSONStreetCount()); displayMgr.setItemProgress(itemInfo.get(itemBeingProcessed).itemClassTSID, itemInfo.get(itemBeingProcessed).itemTSID, itemBeingProcessed+1, itemInfo.size()); // Search the snap for this image/item @@ -797,32 +801,21 @@ class StreetInfo if (!moveToNextItem()) { // Either error condition or at end of street/items - so need to return to top level to start over with new snap/street - //failNow = true; return; } else { // Next item is safe to procced to - - // Set up fragFind in item ready to start the next item/streetsnap search combo - // i.e. loads up pointers to correct street snap and item images - // Only do this for items we still need to search for if (itemValidToContinueSearchingFor(itemBeingProcessed)) { - if (!itemInfo.get(itemBeingProcessed).resetReadyForNewItemSearch()) - { - displayMgr.showErrMsg("Unexpected error getting ready for new item search", true); - failNow = true; - return; - } - printToFile.printDebugLine(this, "PROCESSING ITEM " + itemBeingProcessed + " ON STREET SNAP " + streetSnapBeingUsed, 1); + printToFile.printDebugLine(this, "PROCESSING ITEM " + itemBeingProcessed + "(" + itemInfo.get(itemBeingProcessed).readItemTSID() + ") ON STREET SNAP " + streetSnapBeingUsed, 1); } else { printToFile.printDebugLine(this, "Skipping item/item Found " + itemInfo.get(itemBeingProcessed).readItemClassTSID() + "(" + itemInfo.get(itemBeingProcessed).readOrigItemVariant() + ") " + itemInfo.get(itemBeingProcessed).readItemTSID(), 1); - } + } } } @@ -841,6 +834,11 @@ class StreetInfo { // Finished all items on the street // So move onto the next street snap after unloading the current one + + // But first need to null the FragFind structure in the structure for the last item - as it contains a reference to the street snap + // which means the call below to unload the street snap won't work - and then memory hell ensues. + itemInfo.get(itemBeingProcessed-1).clearFragFind(); + streetSnaps.get(streetSnapBeingUsed).unloadPNGImage(); // reset itemBeingProcessed back to 0 @@ -879,7 +877,7 @@ class StreetInfo // Now print out the summary array // The second sorting of item results shouldn't throw up any duplicate x,y - if it happens they'll just be reported as warnings. // Any actual errors are reported from within printSummaryData - if (! printToFile.printSummaryData(itemResults)) + if (!printToFile.printSummaryData(itemResults)) { failNow = true; return false; @@ -902,8 +900,7 @@ class StreetInfo return false; } itemBeingProcessed = 0; - printToFile.printDebugLine(this, "STARTING WITH FIRST ITEM ON STREET SNAP " + streetSnapBeingUsed, 1); - + printToFile.printDebugLine(this, "STARTING WITH FIRST ITEM (" + itemInfo.get(itemBeingProcessed).readItemTSID() + ") ON STREET SNAP " + streetSnapBeingUsed, 1); if (itemValidToContinueSearchingFor(itemBeingProcessed)) { if (!itemInfo.get(itemBeingProcessed).resetReadyForNewItemSearch()) @@ -912,11 +909,10 @@ class StreetInfo failNow = true; return false; } - printToFile.printDebugLine(this, "PROCESSING ITEM " + itemBeingProcessed + " ON STREET SNAP " + streetSnapBeingUsed, 1); + printToFile.printDebugLine(this, "PROCESSING ITEM " + itemBeingProcessed + " (" + itemInfo.get(itemBeingProcessed).readItemTSID() + ") ON STREET SNAP " + streetSnapBeingUsed, 1); } } - //return false; } // if past end of item list else @@ -930,7 +926,7 @@ class StreetInfo failNow = true; return false; } - printToFile.printDebugLine(this, "PROCESSING ITEM " + itemBeingProcessed + " ON STREET SNAP " + streetSnapBeingUsed, 1); + printToFile.printDebugLine(this, "PROCESSING ITEM " + itemBeingProcessed + " (" + itemInfo.get(itemBeingProcessed).readItemTSID() + ") ON STREET SNAP " + streetSnapBeingUsed, 1); } } return true; @@ -1257,7 +1253,7 @@ class StreetInfo } return true; } - + void initStreetItemVars() { for (int i = 0; i < itemInfo.size(); i++) diff --git a/sketch_QA_tool.pde b/sketch_QA_tool.pde index 3870b4d..f460e88 100644 --- a/sketch_QA_tool.pde +++ b/sketch_QA_tool.pde @@ -196,6 +196,7 @@ public void draw() // Carry out processing depending on whether setting up the street or processing it //println("nextAction is ", nextAction); //memory.printMemoryUsage(); + //memory.printUsedMemory("start"); switch (nextAction) { case IDLING: @@ -383,7 +384,7 @@ public void draw() // Carries out the setting up of the street and associated items printToFile.printDebugLine(this, "Timestamp: " + nf(hour(),2) + nf(minute(),2) + nf(second(),2), 1); printToFile.printDebugLine(this, "Read street data for TSID " + configInfo.readStreetTSID(streetBeingProcessed), 2); - + if (!initialiseStreet()) { // fatal error @@ -581,6 +582,7 @@ public void draw() printToFile.printDebugLine(this, "Unexpected next action - " + nextAction, 3); exit(); } + //memory.printUsedMemory("end"); } void doExitCleanUp()