CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2011
    Posts
    44

    Do I have to delete TEXT("...") strings?

    Hi,

    if I have the following:

    Code:
    LPCTSTR text = TEXT("This is my text");
    do I have to

    Code:
    delete text;
    I guess no, because it crashes when I'm doing this ^^

    but doesn't this memory have to be freed?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Do I have to delete TEXT("...") strings?

    You must not delete what you didn't new.
    Quote Originally Posted by chaos2oo2
    but doesn't this memory have to be freed?
    What memory do you mean?
    Victor Nijegorodov

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Do I have to delete TEXT("...") strings?

    TEXT("...") is a macro that expands to L"..." or "..." if UNICODE is or is not defined.
    Both, L"..." and "..." are string literals.
    A string literal has static storage duration, which means it exists for the all duration of the program.
    You have not to allocate/free memory for string literals.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured