Do I have to delete TEXT("...") strings?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

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

  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 online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,480

    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
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,051

    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 Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center