Delete Operator ????????????

Discussion in 'C++' started by rahulonly4u, Sep 16, 2010.

  1. rahulonly4u

    rahulonly4u New Member

    Joined:
    Sep 6, 2010
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    software developer
    Location:
    india
    HI ,

    Is Delete Operator release Memory immediately .


    I mean if i am using delete at some point in my program does my process immediately release the Memory and does OS will be able to use it for other process or their is some other mechanism for OS get released memory back where can i get knowledge about this .


    please give me the direction , reference's ,books name .


    does it depends on compiler Or Operating System ??

    Regards
    Rahul
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I think you are not understanding the concept of release. Any memory not associated by any valid pointer is actually released. I will explain in a better example.

    Let us say you have a drive filled with all images. Your memory card. Now you delete the files using your OS.

    Do you think it is same as format of card. No. Card files actually reside on the card but it is just that the pointer to those files are wiped. You can actually recover the files by reading sectors of the disk.

    With the same analogy there is not need to clean the memory unless it is needed once again and so OS does the process to work for better user experience.
     
  3. rahulonly4u

    rahulonly4u New Member

    Joined:
    Sep 6, 2010
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    software developer
    Location:
    india


    Sir actually i asked this question in the context that when i am deleting object even my process dose not showing decrement in Memory Usage as i seen this in task manager so dose my process keeping this memory until OS doesn't require that memory for some another process OR OS take it back from the process

    Regards
    Rahul
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Task manager unit may in MG (if not GB) and you are allocating bytes and releasing it. Even if it shows then you cannot see it with naked eyes.
     
  5. rahulonly4u

    rahulonly4u New Member

    Joined:
    Sep 6, 2010
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    software developer
    Location:
    india
    Sir I am getting memory detail from memory used by process that we can get from PROCESS Tab i think we get memory in KB's
    and i am writing a memory intensive code for that

    Code:
    
    _tmain()
    {
    
    
    int i=0;
    	   long int  j=0,k;
    	   char c;
    		 CArray<CString,CString> mycarray;          
               
                    cout<< "\nbefore creating object"; 
          [COLOR="Blue"]LABLE1[/COLOR]					 
    			    for(k=1;k<5;k++)
    			    {
                         
    			          for(j=1;j<25000 ;j++)
    			          {
    				              mycarray.Add( _T("this is test"));
    							  mycarray.Add( _T("this is test"));
    							  mycarray.Add( _T("this is test"));
    							  mycarray.Add( _T("this is test"));
    						      mycarray.Add( _T("this is test"));
    			          }
    					    cout<<"\nadded   10,000   elements ";
    					    mycarray.RemoveAll();
         [COLOR="Blue"] LABLE2[/COLOR]
    			            cout<<"\nremoved\n";
    		        }
    			  
    	
    }// end of main 
    
    i want to when i run this program there is a big diffrence in memory used by process which i can see in process tab of task manager the two places are lable 1 and lable2

    in ideal way memory used by process at labe1 -lable2 ~=0
    i.e before adding elements to the CArray and after Removing elements from the CArray memory usage by process must be same isnt it ?
    but this is not happening
     
    Last edited by a moderator: Sep 20, 2010

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice