Now, constant time code can't have conditional jumps based on secret data, or access memory locations based on secret data - either of those can cause timing variations. Your example violates this (because of the conditional jump).
The only way I can see how constant time code could have a leak due to Garbage collection is if the constant time code either had a reference to a data structure or didn't have a reference, and whether it did would depend on secret data. The constant time code could conditionally clear out the reference (without violating the constant time requirements).
If it did that, then whether that data structure is GC'ed would depend on the secret data and that would be a leak.
However, the constant time code couldn't access that memory structure (because of the prohibition on accessing secret-based memory locations), and so it's a bit unclear to me how that would arise in practice; conditionally clearing out a reference that cannot be used doesn't strike me as something that a naive (but honest) programmer would do...
Now, one thing that occurs to me is that Garbage Collection could more plausibly amplify the leakage in code that already has some.
Consider this pseudocode:
A, B are the only references to data structures
if (secret_condition)
B := A /* Have B refer to A's data structure, leaving no */
/* reference to what B used to refer to */
do computations on the data structures referred to by A, B
That code is at least somewhat plausible.
It also has a timing leak (because on what memory locations that B refers to is based on secret data), however depending on what those references are, it might be fairly quiet.
On the other hand, if Garbage Collection happens, then either one of the data structures will be cleaned up or not, based on secret data. Garbage Collection could plausibly be louder (that is, easier to detect by an attacker).
On the other hand, I haven't heard of someone using this 'amplification' effect in a practical attack.
x =
allocate that memory? If so it isn't constant-time even without considering gc. You would need to consider code where all cases allocate the same amount of data, but some input values result in different amounts of garbage. And consider that the same algorithm in a non-gc language would still need to deallocate the memory, which suggests that it's not gc that's the problem. $\endgroup$