Skip to content

Remove Deck::clone() and replace clone-based deck copies with explicit ownership-safe copies - #111

Closed
APN-Pucky with Copilot wants to merge 3 commits into
masterfrom
copilot/remove-clone-methods
Closed

APN-Pucky with Copilot wants to merge 3 commits into
masterfrom
copilot/remove-clone-methods

Conversation

Copilot AI commented May 22, 2026 •

Copy link
Copy Markdown

Deck::clone() allocated with new and encouraged leak-prone call patterns. This change removes the clone API and replaces all clone usage with explicit copy semantics so ownership is visible at call sites.

  • API cleanup: remove clone entrypoint

    • Deleted Deck::clone() declaration and definition from deck.h / deck.cpp.
    • Removed stale commented clone references in deck simulation code paths.
  • Algorithms: replace implicit heap cloning with explicit copy strategy

    • Updated optimization flows (hill_climbing, simulated_annealing, genetic_algorithm, beam_climb, forts_climbing) to use:
      • stack Deck copies for transient state, and
      • explicit new Deck(...) only where pointer-returning APIs require heap ownership.
    • Added local ownership containers for generated beam/genetic decks to avoid lifetime leaks while preserving pointer-based structures.
  • Runtime/simulation wiring: remove clone calls from process setup

    • Replaced deck cloning in simulation setup and run paths with explicit copy construction (new Deck(*src) or stack copy where appropriate).
    • Kept existing external behavior and pointer-based interfaces intact while making allocation/ownership explicit.
  • Behavior-preserving adjustment

    • In duplicate-pool mutation logic, preserved prior semantics by mutating from a temporary copied source deck rather than mutating source/destination as the same object.

Example of the core migration pattern:

// before
Deck* best_deck = cur_deck->clone();
return std::make_pair(best_deck->clone(), best_score);

// after
Deck best_deck(*cur_deck);
return std::make_pair(new Deck(best_deck), best_score);

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Remove clone methods to prevent memory leaks Remove Deck::clone() and replace clone-based deck copies with explicit ownership-safe copies May 22, 2026
Copilot AI requested a review from APN-Pucky May 22, 2026 21:34
@APN-Pucky APN-Pucky closed this May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deck->clone()s should be deleted since it uses new and leaks

2 participants