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 8228841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:35:52+00:00 2026-06-07T16:35:52+00:00

Stack^ my_stack=gcnew Stack; my_class^ a=gcnew my_class; my_stack->Push(a); my_stack->Push(gcnew my_class); my_stack->Pop(); //will it cause memory

  • 0
Stack^ my_stack=gcnew Stack;
my_class^ a=gcnew my_class;
my_stack->Push(a);
my_stack->Push(gcnew my_class);
my_stack->Pop(); //will it cause memory leak?
a=gcnew my_class;
my_stack->Pop(); //will it cause memory leak?

sorry that the code is not tested. But I guess you all get what I mean here.
when you pop a pointer, you lose the pointer; will the memory be released?
there is also a method my_stack->Clear() which is also confusing for me.

Any help would be appreciated.

edit:

@Konrad Rudolph

Would the Pop() method call the destructor itself or the clr will automatically retrieve the memory space?

Konrad Rudolph also suggests me to consider using generic collection classes only.

For the new System::Collections::Generic::Stack<T>
It says ‘Removes and returns the object at the top of the Stack’
And if so, what if I have another pointer pointed to object before?
that is,

my_class^ a=gcnew my_class;
Stack<my_class>^ my_stack=gcnew Stack<my_class>;
my_stack->Push(a);
my_stack->Pop(); //what is a now? nullptr?
  • 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-06-07T16:35:54+00:00Added an answer on June 7, 2026 at 4:35 pm

    Pop does not call the destructor. You can use something like

    T *topObject = my_stack->top();
    my_stack->pop();
    delete topObject;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My goal is to remove from the raw stack the records that are not
What warning signs are there that my stack memory space is bloated, and at
Okay, so I've written my own stack class, not using the built in one.
Im trying to call the function: friend ostream& operator<<(ostream& out, stack::myItem& theItem); that is
I'm investigating a stack trace (seen while debugging) that looks something like the following:
I'm trying to design a data-structure around a stack that blocks until the stack
I have this byte code: new java.lang.Object // stack is [newObjectRef] dup // Stack
here is my stack trace [NullReferenceException: Object reference not set to an instance of
I have a code that try to find the Eulerian path like this. But
Here's my data table in my SQL DB, and below that is the code

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.