Interesting, although, I don't know how to do such hooking ... 

On Thursday, October 22, 2015 at 6:21:05 PM UTC+3:30, Stefan Karpinski 
wrote:
>
> There's also atexit:
>
>   atexit(f)
>
>   Register a zero-argument function f() to be called at process exit. 
> atexit() hooks
>   are called in last in first out (LIFO) order and run before object 
> finalizers.
>
> On Thu, Oct 22, 2015 at 10:48 AM, Yichao Yu <[email protected] 
> <javascript:>> wrote:
>
>> On Thu, Oct 22, 2015 at 9:42 AM,  <[email protected] <javascript:>> 
>> wrote:
>> > Hi Julia-Users
>> > I know that Julia has a Garbage Collector that is being aware of 
>> unusable
>> > memory pointers. [ref] I think some other languages e.g. Java also do it
>> > automatically, and Java programmers rarely need to do it manually [ref],
>> > while writing such routines is very common in C++ [ref].
>> > Is it possible to have something like Java finalize or C++ ~ in Julia?
>> > This routine may be called
>> >    - by Julia REPL when a kill signal (Ctrl+D) is sent.
>> >    - or workspace() is called.
>> >    - or by Garbage Collector before removing a pointer.
>>
>> We do have finalizer
>> However, there's a few things to note.
>> * The finalizer is run by the GC. Don't call `gc()` in it (it will be
>> no-op). (Actually, don't ever call gc() unless you are absolutely sure
>> you know what you are doing and you need it)
>> * We will never have garentee on when, how or in which order the
>> finalizers are called, which I think is common in tracing GCs.
>> * Do not use the finalizer to manage resources you care about. The GC
>> doesn't (yet) have any notion of resources pressure other than the GC
>> memory usage so it may not collect your resources at the time you
>> want. You should explicitly free those resources (the `do` block,
>> try/finally, wrap one of these in macro etc)
>>
>> > type mytype
>> >   mytype()=new()
>> >   function ~mytype()
>> >      close(file)
>> >      free(memory)
>> >      kill(externals)
>> >      delete(temps)
>> >      gc()
>> >   end
>> >   file::File
>> >   memory::Pointer
>> >   externals::Any
>> >   temps::File
>> > end
>> > module mymodule
>> >   function unload()
>> >      close(file)
>> >      free(memory)
>> >      kill(externals)
>> >      delete(temps)
>> >      gc()
>> >   end
>> >   file::File
>> >   memory::Pointer
>> >   externals::Any
>> >   temps::File
>> > end
>> >
>>
>
>

Reply via email to