Garbage Collector, Managed Heap etc.

This is a discussion on Garbage Collector, Managed Heap etc. within the C Programming forums, part of the General Programming Boards category; Preamble: Please do not move this thread on "Windows programming" cause I am a C programmer under Linux who needs ...

  1. #1
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251

    Garbage Collector, Managed Heap etc.

    Preamble:
    Please do not move this thread on "Windows programming" cause I am a C programmer under Linux who needs to make some code also under Windows but this question IS NOT on strictly-Windows matters. It is instead about Garbage Collector and Managed Heap Objects and variables, which is somethiong more general than just Windows matters.

    Problems:
    (1) When I alloc on the Managed Heap a new instance of var/obj. with something similar to

    Code:
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
      InitializeComponent();
      Initialize();
    }
    ..
    ..
       private: System::String^ Str;
    ..
    ..
    void Initialize(void)
    {	
    ..
       this->Str = gcnew System::String("");
    is there a method I can call to explicitely free the resource when not needed or do I have to let this be done by the garbage collector?

    (2)
    In another example
    Code:
    
    
    private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) 
    {
      System::String^ TempStr;
    ..
    ..
      TempStr=String::Format("DataLen= {0:D}\n",Req.DataLen);
      textBox4->AppendText(TempStr);
    ..
    ..
    I did not have to use gnew cause this is implicitely called (I have been told in another thread) by String::Format
    Where is it easy to the find the answer to this question: a method calls implicitely gcnew or not?

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,420
    Sorry, this is C++/CLI, not C (and does it really matter where the thread is located?).

    For 1) I don't know if there is one or not, but I do not think it's recommended that you do it manually.
    As for 2) What does it matter? String is a class and handles its internal memory management by itself. This is standard C++, even without it being managed.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    The arrogancy of telling the mods not to move C++/CLI code from the C forums is pretty stunning. If you don't even know what language you're writing in, what kind of programmer are you?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  2. heap
    By George2 in forum Windows Programming
    Replies: 2
    Last Post: 11-10-2007, 10:49 PM
  3. Garbage Collection
    By Orborde in forum C++ Programming
    Replies: 4
    Last Post: 05-10-2005, 11:18 PM
  4. Do you know...
    By davejigsaw in forum C++ Programming
    Replies: 1
    Last Post: 05-10-2005, 10:33 AM
  5. heap question
    By mackol in forum C Programming
    Replies: 1
    Last Post: 11-30-2002, 04:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21