Counting allocations with repeated references

A mutable Batch has three reference fields: first and second identify entry E1, while third identifies a distinct entry E2. Both mutable entries identify the same mutable Counter. There are no other referenced model objects.


You create one shallow copy of the original batch and, separately, one deep copy of the original batch. The deep copy duplicates every reachable mutable object exactly once and preserves internal sharing. Count only newly allocated Batch, Entry and Counter instances, ignoring helper storage. How many model objects are allocated across both copy operations? Answer as an exact integer, to zero decimal places.


A batch refers twice to one entry and once to another entry, and both entries refer to one shared counter.


Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Shallow vs Deep Copies Questions: