# AudioProcessorGraph reallocating on the audio thread?

**URL:** <https://forum.juce.com/t/audioprocessorgraph-reallocating-on-the-audio-thread/69769>\
**Category:** General JUCE discussion\
**Created:** [October 22, 2026, 4:25pm UTC](https://forum.juce.com/t/audioprocessorgraph-reallocating-on-the-audio-thread/69769 "2026-10-22T16:25:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgrand](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mgrand/32/14447_2.png) [@mgrand](https://forum.juce.com/u/mgrand)\
**Post date:** [October 22, 2026, 4:25pm UTC](https://forum.juce.com/t/audioprocessorgraph-reallocating-on-the-audio-thread/69769/1 "2026-10-22T16:25:12Z")

</div>

Hi all,

I noticed something odd in AudioProcessorGraph.

In `GraphRenderSequence::perform()`, the output buffer is resized on every call:

```auto
currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);

```

`AudioBuffer::setSize()` uses `avoidReallocating = false` by default, so as far as I can tell, any change in `numSamples` reallocates the buffer on the audio thread. A sequence of variable-sized blocks like 64 - 4 - 60 - 64 would allocate 3 times.

Variable block sizes are explicitly allowed by the `AudioProcessor` doc so this seems unexpected…

Is there a reason it doesn’t pass `avoidReallocating = true`, since `prepareToPlay()` already allocates for the maximum block size?

Thanks!

---

<div class="post-metadata">

**Author:** ![synthalorian](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@synthalorian](https://forum.juce.com/u/synthalorian)\
**Post date:** [October 29, 2026, 5:13am UTC](https://forum.juce.com/t/audioprocessorgraph-reallocating-on-the-audio-thread/69769/2 "2026-10-29T05:13:16Z")

</div>

I checked this in the current source and you’re right. GraphRenderSequence::perform() calls

```
currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);

```

with the defaults (keepExistingContent = false, avoidReallocating = false). In AudioBuffer::setSize, whenever newNumSamples != size, the non-keep path only reuses the memory if avoidReallocating is true and allocatedBytes \>= newTotalBytes. Otherwise it allocates a new HeapBlock. So 64 → 4 → 60 → 64 allocates on every size change. prepareBuffers() already sizes this buffer for the max block size, so passing avoidReallocating = true should be safe:

```
currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples, false, false, true);

```

It would also be worth checking whether the channel count can grow past what prepareBuffers() allocated. If it can, it would still allocate, but that’s a separate case.

You can confirm it by running the graph under RTSan or a malloc hook with varying block sizes.
