f

#### There's 'new' but no 'delete'

Hi,

If I use: "myobject = new MyObject" do I just delete it with "myobject =
nil"? There's no "delete", how do I free any memory used within myobject?

Thanks,

Paul


 0
pf
4/15/2005 3:35:06 AM
comp.lang.basic.realbasic 2744 articles. 0 followers. spam127 (8) is leader.

13 Replies
844 Views

Similar Articles

[PageSpeed] 34

On 15.04.2005 05:35 Mat, in 425e45ff$0$30370$afc38c87@news.optusnet.com.au, �pf� <paulfredlein@NOSPAMoptusnet.com.au> wrote: > Hi, > > If I use: "myobject = new MyObject" do I just delete it with "myobject = > nil"? There's no "delete", how do I free any memory used within myobject? > > Thanks, > > Paul Yes, "MyObject=nil" frees memory (and is correct).   0 Anic 4/14/2005 11:45:32 AM In article <425e45ff$0$30370$afc38c87@news.optusnet.com.au>,
"pf" <paulfredlein@NOSPAMoptusnet.com.au> wrote:

> If I use: "myobject = new MyObject" do I just delete it with "myobject =
> nil"?

No, you don't worry about it.  Your object will be deleted automatically
when it can no longer be used (because there are no more references to
it).

Local variables are automatically released at the end of the method
they're in, and object properties are automatically released when the
object dies, so in most cases you don't need to explicitly set one to
nil.

> There's no "delete", how do I free any memory used within myobject?

You use REALbasic.  :)  Having to explicitly free something you've
created is an artifact of more primitive languages.

Best,
- Joe

,------------------------------------------------------------------.
|    Joseph J. Strout         Check out the Mac Web Directory:     |
|    joe@strout.net           http://www.macwebdir.com             |
------------------------------------------------------------------'

 0
Joe
4/14/2005 7:12:39 PM
In article <BE84247C.6871%arnaud@tribu.ch>, Anic <arnaud@tribu.ch>
wrote:

> Yes, "MyObject=nil" frees memory (and is correct).

Well, not really.  It won't free any memory if there are any other
references to that object.  And even if it is the last reference, you
usually don't have to set it to nil explicitly -- for example, if
"MyObject" is a local variable, it'll be set to nil at the end of the
method anyway.  And there's really nothing magic about 'nil'; assigning
any other value to MyObject would release the reference to the previous
one too.

Best,
- Joe

,------------------------------------------------------------------.
|    Joseph J. Strout         Check out the Mac Web Directory:     |
|    joe@strout.net           http://www.macwebdir.com             |
------------------------------------------------------------------'

 0
Joe
4/14/2005 7:14:23 PM
On 14.04.2005 09:14Soir, in
joe-D7EF06.14142314042005@comcast.dca.giganews.com, �Joe Strout�
<joe@strout.net> wrote:

> In article <BE84247C.6871%arnaud@tribu.ch>, Anic <arnaud@tribu.ch>
> wrote:
>
>> Yes, "MyObject=nil" frees memory (and is correct).
>
> Well, not really.  It won't free any memory if there are any other
> references to that object.

Are not the other references to that object set to nil by the way?

Something like:

Dim m As picture
Dim n As picture

m=newPicture(1,1,32)
n=m
m=nil

n is nil, there, no?

> And even if it is the last reference, you
> usually don't have to set it to nil explicitly -- for example, if
> "MyObject" is a local variable, it'll be set to nil at the end of the
> method anyway.  And there's really nothing magic about 'nil'; assigning
> any other value to MyObject would release the reference to the previous
> one too.

Yes, you're right of course. But I thought the original question was to
release memory in the middle of a method. I may have misunderstood.


 0
Anic
4/16/2005 2:12:56 PM
In article <BE86EA08.68D4%arnaud@tribu.ch>, Anic <arnaud@tribu.ch>
wrote:

> > Well, not really.  It won't free any memory if there are any other
> > references to that object.
>
> Are not the other references to that object set to nil by the way?

No.

> Something like:
>
> Dim m As picture
> Dim n As picture
>
> m=newPicture(1,1,32)
> n=m
> m=nil
>
> n is nil, there, no?

Nope.  You set m to nil, but you didn't assign to n, so its value hasn't
changed.  It still points at the Picture object created on the
NewPicture line.  It's just as valid a reference to that object as m
was; setting one reference to nil doesn't affect the others at all.

Best,
- Joe

,------------------------------------------------------------------.
|    Joseph J. Strout         Check out the Mac Web Directory:     |
|    joe@strout.net           http://www.macwebdir.com             |
------------------------------------------------------------------'

 0
Joe
4/16/2005 7:58:29 PM
On 16.04.2005 09:58Soir, in
joe-B47B6D.14582616042005@comcast.dca.giganews.com, �Joe Strout�
<joe@strout.net> wrote:

> In article <BE86EA08.68D4%arnaud@tribu.ch>, Anic <arnaud@tribu.ch>
> wrote:
>
>>> Well, not really.  It won't free any memory if there are any other
>>> references to that object.
>>
>> Are not the other references to that object set to nil by the way?
>
> No.
>
>> Something like:
>>
>> Dim m As picture
>> Dim n As picture
>>
>> m=newPicture(1,1,32)
>> n=m
>> m=nil
>>
>> n is nil, there, no?
>
> Nope.  You set m to nil, but you didn't assign to n, so its value hasn't
> changed.  It still points at the Picture object created on the
> NewPicture line.  It's just as valid a reference to that object as m
> was; setting one reference to nil doesn't affect the others at all.

That's strange; I had a big problem with dates, something like:

dim d as date
dim e as date

d=new date
e=d
d.month=3

Then, e.month=3 as well; what is the difference of setting d to another
value (like d=nil) and setting d.month to another value?


 0
Anic
4/17/2005 1:31:36 AM
Anic <arnaud@tribu.ch> wrote:

> That's strange; I had a big problem with dates, something like:
>
> dim d as date
> dim e as date
>
> d=new date

a new object

> e=d

two references to one object

> d.month=3

changes the object

> Then, e.month=3 as well;

e is the same object, so the same value.

> what is the difference of setting d to another value (like d=nil) and
> setting d.month to another value?

?

to copy a date

e=new date
e.totalseconds=d.totalseconds

Maybe you could fill a feature request for a copy method in the date
class.

Mfg
Christian

--
Nine thousand functions in one REALbasic plug-in. The MBS Plugin.

 0
support
4/17/2005 7:00:37 PM
pf <paulfredlein@NOSPAMoptusnet.com.au> wrote:

> Hi,
>
> What if I wanted to reuse the object within the same function?
>
> dim mo as MyObject
> mo = nil
> mo = new MyObject
>
> //do stuff with mo
>
> //now I need to use it again
> if mo <> nil then // delete it if there

this test is not needed

> mo = nil

this is not needed as the assignment below will do this.

> end
>
> mo = new MyObject
>
> // do more stuff to mo
>
> Is that correct?

Yes.

Mfg
Christian

--
Nine thousand functions in one REALbasic plug-in. The MBS Plugin.

 0
support
4/17/2005 7:02:02 PM
On 17.04.2005 09:00Soir, in

> Anic <arnaud@tribu.ch> wrote:
>
>> That's strange; I had a big problem with dates, something like:
>>
>> dim d as date
>> dim e as date
>>
>> d=new date
>
> a new object
>
>> e=d
>
> two references to one object
>
>> d.month=3
>
> changes the object
>
>> Then, e.month=3 as well;
>
> e is the same object, so the same value.
>
>> what is the difference of setting d to another value (like d=nil) and
>> setting d.month to another value?
>
> ?
>
> to copy a date
>
> e=new date
> e.totalseconds=d.totalseconds
>
> Maybe you could fill a feature request for a copy method in the date
> class.

In fact, my question was "Why d.month=3 also changes e.month to 3 while
d=nil doesn't change e to nil?"; sorry to have been unclear, I didn't find
correct words.
Thanks.


 0
Anic
4/17/2005 8:07:47 PM
Hi,

What if I wanted to reuse the object within the same function?

dim mo as MyObject
mo = nil
mo = new MyObject

//do stuff with mo

//now I need to use it again
if mo <> nil then // delete it if there
mo = nil
end

mo = new MyObject

// do more stuff to mo

Is that correct?

Thanks,

Paul

"Joe Strout" <joe@strout.net> wrote in message
news:joe-9CD8BF.14123914042005@comcast.dca.giganews.com...
> In article <425e45ff$0$30370$afc38c87@news.optusnet.com.au>, > "pf" <paulfredlein@NOSPAMoptusnet.com.au> wrote: > >> If I use: "myobject = new MyObject" do I just delete it with "myobject = >> nil"? > > No, you don't worry about it. Your object will be deleted automatically > when it can no longer be used (because there are no more references to > it). > > Local variables are automatically released at the end of the method > they're in, and object properties are automatically released when the > object dies, so in most cases you don't need to explicitly set one to > nil. > >> There's no "delete", how do I free any memory used within myobject? > > You use REALbasic. :) Having to explicitly free something you've > created is an artifact of more primitive languages. > > Best, > - Joe > > ,------------------------------------------------------------------. > | Joseph J. Strout Check out the Mac Web Directory: | > | joe@strout.net http://www.macwebdir.com | > ------------------------------------------------------------------'   0 pf 4/18/2005 1:41:38 AM In article <42621fe6$0$29866$afc38c87@news.optusnet.com.au>,
"pf" <paulfredlein@NOSPAMoptusnet.com.au> wrote:

> What if I wanted to reuse the object within the same function?

That's no problem.

> dim mo as MyObject
> mo = nil

Skip this line.  It's just wasted code; mo is nil already.  (Object
references are initialized to zero, just as integers are initialized to
0.)

> mo = new MyObject
>
> //do stuff with mo
>
> //now I need to use it again
> if mo <> nil then // delete it if there
> mo = nil
> end

Skip this too.  It does not delete the object, it merely makes mo no
longer refer to it, which is what this next line does already:

> mo = new MyObject
>
> // do more stuff to mo
>
> Is that correct?

It will work, but it's working much harder (and worrying much more) than
you need to.  The following code would be just as correct:

>dim mo as MyObject
>mo = new MyObject
>
>//do stuff with mo
>
>//now I need to use it again
>mo = new MyObject
>
>// do more stuff to mo

And note that you're not reusing the object; you're reusing the object
*reference* (which is what 'mo' is).

Best,
- Joe

,------------------------------------------------------------------.
|    Joseph J. Strout         Check out the Mac Web Directory:     |
|    joe@strout.net           http://www.macwebdir.com             |
------------------------------------------------------------------'

 0
Joe
4/18/2005 1:36:01 PM
In article <BE878918.690F%arnaud@tribu.ch>, Anic <arnaud@tribu.ch>
wrote:

> That's strange; I had a big problem with dates, something like:
>
> dim d as date
> dim e as date
>
> d=new date
> e=d
> d.month=3
>
> Then, e.month=3 as well; what is the difference of setting d to another
> value (like d=nil) and setting d.month to another value?

The two are completely different.  The statement:

e=d

says, "Make 'e' refer to the same object that 'd' refers to."  The next
statement,

d.month=3

says, "Make the month of the object referred to by 'd' be 3."  But from
the previous statement, we know that the object referred to by d is also
referred to by d.  It's just one object, no manner how many different
ways you have of referring to it.  If that object's month is 3, then
it's 3, no matter whether you refer to it via d or e.

Compare this with the statement:

d=nil

which says, "Make d refer to the nil object."  This obviously doesn't
affect e; it doesn't say anything at all about making e refer to
something else.

Basically, look at what you're assigning to with the '=' operator.  In
"d=nil" you're assigning to d, an object reference.  In "d.month=3"
you're assigning to the Month property of an object.  See the difference?

Best,
- Joe

,------------------------------------------------------------------.
|    Joseph J. Strout         Check out the Mac Web Directory:     |
|    joe@strout.net           http://www.macwebdir.com             |
------------------------------------------------------------------'

 0
Joe
4/18/2005 1:40:11 PM
On 18.04.2005 03:40Soir, in
joe-2D6B53.08401118042005@comcast.dca.giganews.com, �Joe Strout�
<joe@strout.net> wrote:

> In article <BE878918.690F%arnaud@tribu.ch>, Anic <arnaud@tribu.ch>
> wrote:
>
>> That's strange; I had a big problem with dates, something like:
>>
>> dim d as date
>> dim e as date
>>
>> d=new date
>> e=d
>> d.month=3
>>
>> Then, e.month=3 as well; what is the difference of setting d to another
>> value (like d=nil) and setting d.month to another value?
>
> helpful, so I'll try too.
>
> The two are completely different.  The statement:
>
> e=d
>
> says, "Make 'e' refer to the same object that 'd' refers to."  The next
> statement,
>
> d.month=3
>
> says, "Make the month of the object referred to by 'd' be 3."  But from
> the previous statement, we know that the object referred to by d is also
> referred to by d.  It's just one object, no manner how many different
> ways you have of referring to it.  If that object's month is 3, then
> it's 3, no matter whether you refer to it via d or e.
>
> Compare this with the statement:
>
> d=nil
>
> which says, "Make d refer to the nil object."  This obviously doesn't
> affect e; it doesn't say anything at all about making e refer to
> something else.
>
> Basically, look at what you're assigning to with the '=' operator.  In
> "d=nil" you're assigning to d, an object reference.  In "d.month=3"
> you're assigning to the Month property of an object.  See the difference?

Yes, I get it. Thanks for these great explanations. Your explanation was
exactly what I needed to see things clearly. Also thanks to Christian.


 0
Anic
4/18/2005 8:59:30 PM

Similar Artilces:

'is not' or '!='
A newbie question to you; what is the difference between statements like: if x is not None: and if x != None: Without any context, which one should be preferred? IMHO, the latter is more readable. On 2014-08-18 21:35, ElChino wrote: > A newbie question to you; what is the difference between statements > like: > if x is not None: > and > if x != None: > > Without any context, which one should be preferred? > IMHO, the latter is more readable. > "x == y" tells you whether x and y refer to objects that are equal. "x is y&qu...

'^=' and '~='?
Hello, What is the difference between '^=' and '~='? Thanks, Duckhye ...

'''''''''''''The Running Update/Append Queries Using VBA code Ordeal''''''''''''''
Hello fellow programmers, I am trying to run an append/update query from code, a command button on a form initiates the queries. the format i am using is; _____________________________________________________ SELECT "criteria" FROM "criteria" WHERE "criteria" UPDATE/APPEND "field selections" RecordSource "qryExample" = above text strings" _______________________________________________________________________ When i am running a SELECT query in this manner it works fine with no problems, and accepts the values of specified linked for...

'''''''''''''The Running Update/Append Queries Using VBA code Ordeal'''''''''''''' #2
Hi, Thanks for ur help there HJ. I know how to do the tasks you specified there. I would like for the update query to use field values from some of the fields on the form (frmInvoices) such as InvoiceNumber, DateFrom, DateTo. My problem is that an append/update query can't find the values in the open Form (frmInvoices) when I specify them as; [Forms]![frmInvoices]![InvoiceNumber] a select query has no problem finding the field values on a form. please help. Aaron Hi Aaron, Could you post the entire code that you are having trouble with? Now it is not possible to see what goes wron...

if str_mo not in ('','.') and str_da not in ('','.') and str_yy not in ('','.') Any shorter ?
Hi, there. =20 I'm just curious if it ever dawned on anybody how to abbreviate this line : if str_mo not in ('','.') and str_da not in ('','.') and str_yy not in ('','.')=20 =20 Igor Kurbeko Clinical Programmer Analyst 678 336 4328 ikurbeko@atherogenics.com =20 no brain no pain =20 how about: if not (str_mo in ('','.') or str_da in ('','.') or str_yy in ('','.')) OR if not (missing(str_mo) or missing(str_da) or missing(str_yy)) Eric On 22 Oct 03 21:13:37 GMT, ikurbeko@ATHER...

What's the difference between 'close' and 'delete'?
Dear all As you know, close(h) and delete(h) both methods can close figure window, when h is a handle of a figure. What's the difference between the two methods? Regards Mayi DA 2007-11-26 "Damayi" <damayi@gmail.com> wrote in message news:3208c5ed-fbde-4f87-9342-36e6fffd98bb@s36g2000prg.googlegroups.com... > Dear all > > As you know, close(h) and delete(h) both methods can close figure > window, when h is a handle of a figure. What's the difference between > the two methods? CLOSE calls the function specified in the CloseRequestFcn property of the ...

How to turn off 'N', 'S', 'E', 'W'
in the map lat and lon labels? I'm doing a final figure and I really don't need an 'N' after every latitude label, jus the number would suffice. How do I turn of the letters followin the number? What function / toolbox are you refering to?!? Being a little more specific would sure help to get an answer ... Sebastian ...

A function with 'and' , 'not' , 'null' , 'car' and 'cdr'
What's this ? (defun enigma (x) (and (not (null x)) (or (null (car x)) (enigma (cdr x))))) "I suppose I should learn Lisp, but it seems so foreign." - Paul Graham, Nov 1983 On Wed, Oct 07 2015, CAI GENGYANG wrote: > What's this ? > > > (defun enigma (x) > (and (not (null x)) > (or (null (car x)) > (enigma (cdr x))))) Bad taste? It returns T if the list X contains nil as an element. It would be clearer to write (some #'null x). Helmut CAI GENGYANG ...

Re: if str_mo not in ('','.') and str_da not in ('','.') and str_yy not in ('','.') Any shorter ?
OR you could use ARRAY data new; set old; array igor \$ (*) str_mo str_da str_yr; do over igor; if igor ~in (' ','.') then do; end; run; Prasad Ravi Igor Kurbeko <ikurbeko@ATHEROGENIC To: SAS-L@LISTSERV.UGA.EDU S.COM> cc: Sent by: "SAS(r) Subject: if str_mo not in ('','.') and str_da not in ('','.') and str_yy ...

error: expected '=', ',', ';', 'asm' or '__attrib
Hi I'm trying to compile an ADC Driver & come acrosss the following error. I've no experience writing drivers before, and hence have no clue how to fix it. Hope someone out there has encountered the problem & suggesst a fix for the same. The Error is I get is : qadc.c: At top level: qadc.c:97: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'qadc_read' make: *** [qadc.o] Error 1 [root@localhost qadc]# ########################################################################### ADC Driver Code ####################...

error: expected '=', ',', ';', 'asm' or '__attrib
Hi I'm trying to compile an ADC Driver & come acrosss the following error. I've no experience writing drivers before, and hence have no clue how to fix it. Hope someone out there has encountered the problem & suggesst a fix for the same. The Error is I get is : qadc.c: At top level: qadc.c:97: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'qadc_read' make: *** [qadc.o] Error 1 [root@localhost qadc]# ########################################################################### ADC Driver Code ##...

replacement for '{' and '}' ?
I am still playing around with what kind of syntax I would like to mark up my documents. Are there equivalent long substitutes for { and } when they are not used to describe arguments to functions? Something like \begin{group} and \end{group}. In other words, if I could force myself to write, say, \begin{group} \it ... \end{group} instead of {\it ... }, then I believe I could identify from the markup context what is an argument that belongs to a just invoked macro and what is text. {Of course, in this context, \textit{...} would be better.} No more ambiguity whether a in \myfunction{a} i...

logical to 'on' / 'off'
Hi, is there a function implemented doing this conversion? my Problem is, that I want to use the following code: set(handles.edit_curr_trq_sl,'Enable',get(hObject,'Value')) where get(hObject,'Value') gives the state of a checkbox thank you! function [str]=tf2oo(logic) switch logic case 0 str='off'; case 1 str='on'; end%switch end%function tf2oo() while i do not know a built in function, I use my own:) meisterbartsch wrote: > > > function [str]=tf2oo(logic) > switch logic > case 0 > str='off'; &g...

'[OFF]' as in 'offensive'???
Hi, given that 'off-topicness' is indicated as '[OT]' and taking a look at those postings that started the threads indicated as '[OFF]' (which may both be seen as being somewhat offensive) may lead to the conclusion that '[OFF]' stands for offensiveness. I don't think that this is the intended meaning so what actually *does* '[OFF]' mean? I never came across that abbreviation before (although I have been around on the USENET for quite some time) but maybe it is worth knowing? Josef 'Jupp' Schugt NOTE: mails >100 KiB ...

Web resources about - There's 'new' but no 'delete' - comp.lang.basic.realbasic

Resources last updated: 1/31/2016 7:28:58 AM