|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
edit1.create
David Smith wrote:
I usually follow what every example in Delphi manual does. There are certain cases where freeAndNil can cause an access violation: Free; := nil; In what way do those two lines make FreeAndNil cause an access violation? -- Rob |
|
#2
|
|||
|
|||
|
edit1.create
If does not actually point to a valid object instance,
Free will cause an access violation. For example: Free; Free; The second Free will fault. Doug Rob Kennedy wrote: David Smith wrote: >I usually follow what every example in Delphi manual does. There are >certain cases where freeAndNil can cause an access violation: >> >Free; >:= nil; > > In what way do those two lines make FreeAndNil cause an access violation? > > |
|
#3
|
|||
|
|||
|
edit1.create
(Top-posting fixed.)
Doug Hale wrote: Rob Kennedy wrote: >David Smith wrote: I usually follow what every example in Delphi manual does. There are certain cases where freeAndNil can cause an access violation: Free; := nil; >> >In what way do those two lines make FreeAndNil cause an access violation? > If does not actually point to a valid object instance, Free will cause an access violation. For example: Free; Free; The second Free will fault. course. Am I to understand that you're really not making any statement at all about FreeAndNil? You haven't shown any examples of calling FreeAndNil, and you haven't shown anything that would cause exceptions in FreeAndNil that wouldn't also occur without FreeAndNil. Your original statement made it sound like there are ways to cause access violations in FreeAndNil that wouldn't occur in ordinary code, and the colon at the end of your statement introduced those two lines as an example of such code. There _are_ ways to cause FreeAndNil to fail that wouldn't fail otherwise, but none of the code you've shown demonstrates that. -- Rob |
|
#4
|
|||
|
|||
|
edit1.create
Rob Kennedy wrote:
(Top-posting fixed.) Doug Hale wrote: >Rob Kennedy wrote: David Smith wrote: I usually follow what every example in Delphi manual does. There are certain cases where freeAndNil can cause an access violation: [] Your original statement made it sound like [] Sorry. I thought Doug's reply was actually coming from David. -- Rob |
|
#5
|
|||
|
|||
|
edit1.create
I have never used FreeAndNil but have always thought that it checks the
pointer before calling free. IT DES NT - I looked at the code! (at least in D7). Where ever Free; := nil; would cause an exception, so would FreeAndNil(); And it is not " " (not an issue for me - the issue for me is why remember FreeAndNil when Free; := nil; is the same). Doug Rob Kennedy wrote: (Top-posting fixed.) Doug Hale wrote: >Rob Kennedy wrote: > David Smith wrote: I usually follow what every example in Delphi manual does. There are certain cases where freeAndNil can cause an access violation: Free; := nil; In what way do those two lines make FreeAndNil cause an access violation? >If does not actually point to a valid object instance, >Free will cause an access violation. >> >For example: >Free; >Free; >The second Free will fault. > > course. > Am I to understand that you're really not making any statement at all about FreeAndNil? You haven't shown any examples of calling FreeAndNil, and you haven't shown anything that would cause exceptions in FreeAndNil that wouldn't also occur without FreeAndNil. > Your original statement made it sound like there are ways to cause access violations in FreeAndNil that wouldn't occur in ordinary code, and the colon at the end of your statement introduced those two lines as an example of such code. > There _are_ ways to cause FreeAndNil to fail that wouldn't fail otherwise, but none of the code you've shown demonstrates that. > > |
![]() |
| Viewing: Web Development Archives > Mailing Lists > Delphi > edit1.create |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|