Hello internet.
I’m defining my own struct, and it does something on PC internals when it is created. I would to perform other operations (some deleting files) when the struct instance is no more in use. Here an simple example.
mutable struct aStruct
value1
value2
value3
function aStruct(value1, value2, value3)
call_this_function_when_Creating_struct_instance()
new(value1,value2,value3)
end
function call_this_function_when_Creating_struct_instance()
println("Doing some internal operations ...")
end
function call_this_function_when_Deleting_struct_instance()
println("Deleting...")
end
end
firstInstance = aStruct(1,1,1)
function dummy()
secondInstance = aStruct(1,1,0)
secondInstance = "here the value of secondInstance is lost"
return nothing
end
dummy()
When firstInstance
is created, the message Doing some...
appears on terminal as expected
But look at dummy
() function. I’ve created secondInstance
and I lose its data.
I would like to run call_this_function_when_Deleting_struct_instance()
at the end of the dummy
() function automatically. My guess is that I have to configure the Garbage Collector, but I have no idea of how to do it
Any suggestions ?