title: Does garbage collection happen when we initialize a char array with a string literal in c?
body: <p>When we write the following line of code in C, </p>
  
  <pre><code>      char local_arr[] = "I am here";
  </code></pre>
  
  <p>the literal "I am here" gets stored in the read only part of the memory(say <strong>RM</strong>). How I visualize it is that it gets stored contiguously in the RM (Is that right?). Then the array <strong><em>local_arr</em></strong> (i.e local array) copies this array index by index from its location in RM.</p>
  
  <p>But what happens to the literal after the <strong><em>local_array</em></strong> copies it? Is it lost thereby causing memory leaks? Or is there some sort of garbage collector like in Java that cleans up unreferenced objects? </p>
  
  <p>For example if i write a piece of code as follows :</p>
  
  <pre><code>for(int i=0;i&lt;100000;i++)
      char local[] = "I am wasting memory";
  </code></pre>
  
  <p>would I not run out of memory? Will each iteration create a new instance of identical literals with each iteration? Or will they all refer to the same literal since the value of the literal everytime is same?</p>
  
  <p>Does <strong>RM</strong> belong to the heap memory or a specialized segment in heap?</p>
  
  <p>Also the local array is stored in the stack, right? What if I use a dynamic array or global array. What happens then?</p>