Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4580290
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:45:46+00:00 2026-05-21T20:45:46+00:00

I was implementing a chess bot in c++ using recursive algorithms and the program

  • 0

I was implementing a chess bot in c++ using recursive algorithms and the program evaluates over a million nodes per move.

Over time the memory it takes up gets to over 1 GIG of RAM…

But I don’t really need the variables that were previously declared after I’m done with the move…

So how do I manually flush the stack memory to get rid of the previously declared variables on the stack just like java’s garbage collector?

UPDATE

I found out that there’s this line in my source:

Move * M = new Move(x1,y1,x2,y2);

pair <Move *, Piece *> pr (M,aPiece);

and it’s in the perform move function which gets called a million times in the recursion…

My question is, how would you clear such variable once all the recursion is done and I no longer need this variable, but while the recursion is doing its thing, I need that variable to stay in the memory?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T20:45:47+00:00Added an answer on May 21, 2026 at 8:45 pm

    Stack-based storage is reclaimed as soon as the function call in which it resides returns.

    Is it possible that you were using heap-allocated memory (i.e. calling new) within your recursive function? Alternatively, if you’re simply looking at the Windows Task Manager or an equivalent, you may be seeing “peak” usage, or seeing some delay between memory being freed by your program and returned to the OS memory pool.

    Follow up (after question was edited):

    It’s not clear what you are doing with the pair<Move*, Piece*>, so I can’t tell if the Move objects need to be held by pointer or not. The primary reasons for holding them via pointer would be polymorphism (not used here since you don’t appear to be creating subclass objects) and to allow their lifetime to be independent of the call stack. Sounds like you don’t have that reason, either. So, why not:

    std::pair<Move, Piece*> pr(Move(x1,y1,x2,y2), aPiece);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm implementing a tagging system for a website. There are multiple tags per object
I want to program a chess engine which learns to make good moves and
implementing publishActivity in PHP using the REST API using this code: $activity = array(
Im implementing my own proto in Java, it will use a heartbeat over a
I have completed implementing Operation of Linear Linked List using C , Now inorder
Implementing Equals() for reference types is harder than it seems. My current canonical implementation
Implementing a 'sandbox' environment in Python used to be done with the rexec module
When implementing a needle search of a haystack in an object-oriented way, you essentially
When implementing Quicksort, one of the things you have to do is to choose
I implementing a EventQueue and get notified when AWTEvents are send. I wait till

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.