Re: Macro function for random seed?
Posted by
Chris Mawata on
URL: http://imagej.273.s1.nabble.com/Copying-files-with-a-Macro-tp3689619p3689626.html
Static variables will survive garbage collection of any instance (they
don't belong to the instance).
Remember that they can be called using classname.variable even when
there are 0 instances.
However in programs with multiple classloaders, they will be garbage
collected when the classloader
is garbage collected but at that point there are no instances of classes
loaded by that classloader
available so it is moot.
Michael Schmid wrote:
> Hi Gabriel,
>
> that's a good question! The seed will be lost if the plugin gets
> removed by the Garbage Collector and the next time it will be
> initialized using the default seed.
> So one should avoid this:
>
> public class Random_ implements PlugIn {
> static Random random = new Random(); //(sorry, there was a mistake
> in this line)
> IJ.register(Random_.class); //protect static class variables from gc
>
> In practice, I don't remember having ever seen a plugin's static
> variables being removed by the Garbage Collector, but maybe that's
> because I usually have plenty of free memory...
>
> Michael
> ________________________________________________________________
>
> On 21 Jan 2010, at 15:29, Gabriel Landini wrote:
>
>> On Thursday 21 Jan 2010 14:26:47 you wrote:
>>> sorry, no way to have a seed for the random number in a macro with
>>> the current ImageJ version.
>>>
>>> You could consider writing a short plugin that is evoked via 'call':
>>> Roughly like this (I have not tried it)
>>
>> I am curious, would the above work for subsequent independent calls
>> of the
>> plugin from the macro?
>> I mean for how long would the seed remain valid?
>>
>> Cheers
>>
>> G.
>