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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:59:00+00:00 2026-06-09T00:59:00+00:00

Update : Sorry, just a big mistake. It is meaningless to write int *a

  • 0

Update : Sorry, just a big mistake. It is meaningless to write int *a = 3; But please just think the analogy to the case like TCHAR *a = TEXT("text"); (I edited my question, so some answers and comments are strange, since they are for my original question which is not suitable)

In main function, suppose I have a pointer TCHAR *a = TEXT("text"); Then it excutes the following code:

int i;
for (i = 0; i < 1000; i++) {
        a = test(i);
}

with the function TCHAR* test(int par) defined by:

TCHAR* test(int par)
{
    TCHAR *b = TEXT("aaa");
    return b;
}

My question is, after executing the above code, but before the program ends, in the memory:

    1. the pointer `a` remains?
    2. The 1000 pointers `b` are deleted each time the function test(...) exits ?
    3. But there are still 1000 memory blocks there?

In fact, my question is motivated from the following code, which shows a tooltip when mouse is over a tab item in a tab control with the style TCS_TOOLTIPS:

case WM_NOTIFY
    if (lpnmhdr->code == TTN_GETDISPINFO) {
    LPNMTTDISPINFO lpnmtdi;
    lpnmtdi = (LPNMTTDISPINFO)lParam;

    int tabIndex = (int) wParam; // wParam is the index of the tab item.

            lpnmtdi->lpszText = SetTabToolTipText(panel->gWin.At(tabIndex));
            break;
    }

I am thinking if the memory usage increases each time it calls

SetTabToolTipText(panel->gWin.At(tabIndex)), which manipulates with TCHAR and TCHAR* and return a value of type LPTSTR.

  • 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-09T00:59:03+00:00Added an answer on June 9, 2026 at 12:59 am
    1. Yes, the pointer a remains till we return from the main function
    2. The variable b (a 4-byte pointer) is automatic. It is created each time we call test function. Once we return from it, the variable disappears (the pointer). Please note, the value to which b points isn’t affected.
    3. No. In most of the cases, I think, there will be only one block allocated during compilation time (most likely in the read-only memory) and the function will be returning the same pointer on every invocation.

    If SetTabToolTipText allocates a string inside using some memory management facilities new/malloc or some os-specific, you should do an additional cleanup. Otherwise there’ll be a memory leak.

    If nothing like this happens inside (it’s not mentioned in the documentation or comments etc), it’s most likely returning the pointer to some internal buffer which you typically use as readonly. In this case, there should be no concerns about a memory consumption increase.

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

Sidebar

Related Questions

UPDATE Turns out I'm just tired. There isn't any problem here sorry for wasting
Update Sorry. I didn't mean the whole reflection library was off limits. I just
I usually perform things like this in C++, but I'm using python to write
Sorry if this sounds stupid but I'm really new to LiftWeb and just struggling
UPDATE: sorry my IE 9 was'nt configured well: it should've been set so that
Sorry for the double post, I will update this question if I can't get
update: I mistyped 2 variables...so embarrassing. thanks everyone for the effort! sorry i find
[Updated, sorry about the change but now to the real problem] I cannot include
UPDATE: I've been playing around with this more, and it seems like tmux's clear-history
I'd like to respect the database as a read-only and never write to it.

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.