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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:05:37+00:00 2026-06-04T05:05:37+00:00

I am doing the following: LRESURT CALLBACK WindowProc{ ……. Case VK_RETURN: int i; for

  • 0

I am doing the following:

LRESURT CALLBACK WindowProc{
    .......
    Case VK_RETURN:
        int i;
        for ( i = 0; i <1000; i++) {
            int  size = determinesize(i);
            int *pttest = new int[size];
            .....(some work)....
            delete[] pttest;
        }
     ........
}

But I got problem when VK_RETURN occurs. If I don’t use delete[] pttest.

My question is that: Do I need to delete ptttest? When I search on google, almost everyone said that for each new, there must be a delete. Another question is that: if I put the for loop code for VK_RETURN in a function, say void whenvkreturn(), then do I need to delete pttest? Since any local variables are destroyed after returning, I guess the 1000 objects created in this loop will be deleted automatically, right? I don’t know the stack very well, so some explanation I found is not clear for me.

=====

OK, there is a vector workaround. But when it is the case:

TCHAR *text = new text[size];

What I am supposed to do?

  • 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-04T05:05:38+00:00Added an answer on June 4, 2026 at 5:05 am

    You always need to delete allocated memory. For every new there should be a delete, even though it is in a function. The problem you are approaching, can easily be solved by using other containers with dynamic sizes, like std::vector. Using dynamic containers in local functions, it will automatically release the memory allocated by itself, and you don’t have to worry.

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

Sidebar

Related Questions

I am doing the following SimpleDateFormat formatter = new SimpleDateFormat(MM-dd-yyyy); calendar.setTime(formatter.parse(01/26/2012); When I do
I am doing the following: $(#fb_friends).append(<div style=\width:150px;float:left;font-size:11px;color:White;\>); $(#fb_friends).append(<input type=\checkbox\ name=\friends\ value=\1244524\ />); $(#fb_friends).append(<img src=\http://graph.facebook.com/
I am doing the following in PHP: exec('java -jar /opt/flex3/lib/mxmlc.jar +flexlib /opt/flex3/frameworks MyAS3App.as -default-size
Instead of doing the following everytime start(); // some code here stop(); I would
Suppose I am doing the following: using (OracleConnection conn = new OracleConnection(connStr)) { OracleTransaction
I am doing the following in my PHP public $message = <p>A new user
I'm doing the following, which basically works. The script tries to insert some lines
I am currently doing the following with some jQuery, $(.template-choice).live(click, function(event){$.post($(this).attr('href'), function(data) { console.log(data);
I am doing the following: __shared__ int exForBlockLessThanP = totalElementLessThanPivotEntireBlock[blockIdx.x]; where totalElementLessThanPivotEntireBlock is an
I my index lets say I have field field named full_name. I'm doing following

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.