androidx / androidx/media

DefaultAllocator re-used by multiple player instances (trimOnReset = false) should not be trimmed unconditionally by SampleDataQueue.reset()

Open
#2,096 6 comments 0 reactions 1 assignee View on GitHub

@marcbaechinger is already working on this.

Since Feb 3, 2025.

needs triage question
Dominant language
Java
Stars
3k
Forks
955
Avg merge
12d 14h
Merged PRs (30d)
2

Description

I tried to use a common DefaultAllocator for multiple players (with trimOnReset = false) as suggested in the constructor:

  /**
   * Constructs an instance without creating any {@link Allocation}s up front.
   *
   * @param trimOnReset Whether memory is freed when the allocator is reset. Should be true unless
   *     the allocator will be re-used by multiple player instances. If set to false, trimming can
   *     be forced by calling {@link #setTargetBufferSize(int)} manually when required.
   * @param individualAllocationSize The length of each individual {@link Allocation}.
   */
  public DefaultAllocator(boolean trimOnReset, int individualAllocationSize) {
    this(trimOnReset, individualAllocationSize, 0);
  }

However, when I tried to trim it manually at the end of all playbacks, I noticed the total bytes allocated was already 0. It turns out SampleDataQueue already called allocator.trim() unconditionally multiple times, destroying each-other's preallocations.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.