UploadPack: Delay freeing refs in sendPack()

Change [1] set refs to null at the beggining of sendPack claiming they
are not needed anymore, but they are still used few lines below to
hoist referenced objects to the front of the pack. With refs nullified,
the hoist doesn't happened. This hasn't caused any problem so far,
probably because it is just an optimization and the objects are in the
pack anyway.

Move the nullification after the hoisting to keep the optimization and
save the memory.

[1] https://git.eclipse.org/r/c/jgit/jgit/+/161341

Change-Id: I8455249d8482f616af362d3912b718064d473b49
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
index 5220057..33aa585 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
@@ -2364,11 +2364,6 @@ private void sendPack(ProgressMonitor pm, PacketLineOut pckOut,
 		}
 		msgOut.flush();
 
-		// Advertised objects and refs are not used from here on and can be
-		// cleared.
-		advertised = null;
-		refs = null;
-
 		PackConfig cfg = packConfig;
 		if (cfg == null)
 			cfg = new PackConfig(db);
@@ -2410,6 +2405,11 @@ else if (ref.getName().startsWith(Constants.R_HEADS))
 				pw.setTagTargets(tagTargets);
 			}
 
+			// Advertised objects and refs are not used from here on and can be
+			// cleared.
+			advertised = null;
+			refs = null;
+
 			RevWalk rw = walk;
 			if (req.getDepth() > 0 || req.getDeepenSince() != 0 || !deepenNots.isEmpty()) {
 				int walkDepth = req.getDepth() == 0 ? Integer.MAX_VALUE