New topic: 

Memory management when returning a value to a calling method

<http://forums.realsoftware.com/viewtopic.php?t=45715>

         Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic          Author  
Message        software-maniac          Post subject: Memory management when 
returning a value to a calling methodPosted: Wed Oct 24, 2012 9:10 pm           
              
Joined: Sun Apr 29, 2007 11:26 am
Posts: 19
Location: Seattle, WA                Given a method:

Function() As String
  Dim strBuffer As String = "abc"
  ...
  Return strBuffer


If this function is called as:

MsgBox(Function())

Am I botching up memory management since the local strBuffer should vanish when 
Function() returns? Does the fact that a returned value is a simple data type 
(like String or Integer...) make a difference?

Thank you!   
                             Top                mauitom          Post subject: 
Re: Memory management when returning a value to a calling mePosted: Wed Oct 24, 
2012 11:06 pm                                 
Joined: Thu Feb 16, 2006 10:04 pm
Posts: 237                First of all you can't name a method "Function".

The strBuffer variable is destroyed once that Method is finished, when it goes 
out of scope. The variable is passed to the Message Box, once it's finished 
with it, it will be destroyed automatically. A reference counting scheme is 
used under the hood.

If you are spending any time worrying about memory management with Real Studio, 
then you are needlessly worrying. 

The only exception is if you start storing circular references, which for the 
most part, I would call fairly rare for most programmers.   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to