Is there a buildSrc classloader leak?

Some behaviour I don’t fully understand.

Try the following experiement:

  • Create a new, sample, project in Android studio (e.g. choose BottomNavigationActivity)
  • run ./gradlew --rerun-tasks assemble a few times
  • observe that the Metaspace stabilises at around 220MB

Now create an empty buildSrc folder and try it again.
This time Metaspace suffers unconstrained growth (uniformly from build to build) until eventually the machine runs out of memory or (if MaxMetaspaceSize is set) the gradle daemon kills itself as Metaspace approaches its limit.

I know this is a slightly contrived example because I’m passing --rerun-tasks.
But, why does this happen ?
It feels like a classloader leak to me.