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

  • SEARCH
  • Home
  • 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 8013673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:41:47+00:00 2026-06-04T19:41:47+00:00

This is a sample code of my program. Here I am dynamically allocating memory

  • 0

This is a sample code of my program. Here I am dynamically allocating memory using std::auto_ptr and entering values( in function) after that I am again allocation memory for the same variable. So Do the previously allocated memory will be deallocated when allocated a new memory for the same. I am doubtful about this since I am using std::auto_ptr. Thanks in advance.

  #include "stdafx.h"
  #include <iostream>
  #include <memory>
  #include <windows.h>

  std::auto_ptr<HANDLE> *eventHandle;

  void function()
  {
    eventHandle = new std::auto_ptr<HANDLE>[5];
    std::auto_ptr<HANDLE> handle(new HANDLE);
    *handle = CreateEvent(NULL, false, false, NULL);
    eventHandle[0] = handle;
  }

  void f2()
  {
    if(NULL == eventHandle)
    {
      std::cout<<" HANDLE NULL";
    }
  }

  int _tmain(int argc, _TCHAR* argv[])
  {
    function();
    f2();
    function();
    return 0;
  }
  • 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-04T19:41:49+00:00Added an answer on June 4, 2026 at 7:41 pm

    Here

    std::auto_ptr<HANDLE> *eventHandle;
    

    you have a raw pointer, so when you reassign it the previous value is just overwritten and the array of objects of type auto_ptr previously pointed to is leaked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's some sample code: using System; namespace UnloadFromFinalizer { class Program { static void
Given this sample code: #include <iostream> #include <stdexcept> class my_exception_t : std::exception { public:
here is a sample code. If I remove the stdafx.h file, the program wont
I am using an example program from this code http://sicktoolbox.sourceforge.net/ > http://sourceforge.net/projects/sicktoolbox/files/ . It's
Can someone help me using fflush in C++ Here is a sample code in
So I this is a sample code. I just started using Visual C++ 2010
In this sample code the URL of the app seems to be determined by
I have this sample code for async operations (copied from the interwebs) public class
Say I have this sample code I'm writing for a Python lesson I'm holding:
In facebook tutorials I see this sample code: @Override public void onActivityResult(int requestCode, int

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.