Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: JavaClass.init with try .. finally ?



Permlink Replies: 2 - Last Post: May 22, 2016 4:51 AM Last Post By: Rudy Velthuis (...
loki loki

Posts: 787
Registered: 7/1/02
JavaClass.init with try .. finally ?
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 20, 2016 5:39 PM
hello,

in the emb code i see often some stuff like this :

   aCanvas := TJCanvas.JavaClass.init(Bitmap);
   try
     ....
   finally
     aCanvas := nil;
   end;


i don't understand, is try ... finally neccessary ? why ?
even the instruction Canvas := nil; is it neccesary also ?

thanks by advance
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: JavaClass.init with try .. finally ?
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 21, 2016 8:50 AM   in response to: loki loki in response to: loki loki
Am 21.05.2016 um 02:39 schrieb loki loki:
hello,

in the emb code i see often some stuff like this :

   aCanvas := TJCanvas.JavaClass.init(Bitmap);
   try
     ....
   finally
     aCanvas := nil;
   end;


i don't understand, is try ... finally neccessary ? why ?
even the instruction Canvas := nil; is it neccesary also ?

thanks by advance

Hello,

I'm not sure if objects comming "from Java land" are handled by ARC as
well. If not it might be that they're a normal interface and they want
to ensure it gets freed or they want to expilicitely be able to check if
the reference is nil at some point in code.

Greetings

Markus
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: JavaClass.init with try .. finally ?
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 22, 2016 4:51 AM   in response to: loki loki in response to: loki loki
loki loki wrote:

hello,

in the emb code i see often some stuff like this :

   aCanvas := TJCanvas.JavaClass.init(Bitmap);
   try
     ....
   finally
     aCanvas := nil;
   end;


i don't understand, is try ... finally neccessary ?

Yes, because Canvases should be released as soon as possible. To be
sure there is no delay, e.g. when an exception occurs, they release
them in a try-finally block.

--
Rudy Velthuis http://www.rvelthuis.de

"The trouble with the world is that the stupid are cocksure and
the intelligent are full of doubt."
-- Bertrand Russell
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02