# Segmentation error, Garbage Collection

**URL:** <https://discourse.julialang.org/t/segmentation-error-garbage-collection/4073>\
**Category:** General Usage\
**Tags:** question, embedding\
**Created:** [June 3, 2017, 1:49pm UTC](https://discourse.julialang.org/t/segmentation-error-garbage-collection/4073 "2017-06-03T13:49:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tastelessjolt](https://avatars.discourse-cdn.com/v4/letter/t/f14d63/32.png) [@tastelessjolt](https://discourse.julialang.org/u/tastelessjolt)\
**Post date:** [June 3, 2017, 1:49pm UTC](https://discourse.julialang.org/t/segmentation-error-garbage-collection/4073/1 "2017-06-03T13:49:18Z")

</div>

What I’m trying to do is to implement a complete interface to call any function of Julia from Scilab language.  
I think the problem is in garbage collection. I would like to know whether there are any such problems. And also I would like to know in detail about how to do Garbage Collection.

Thank you.

The error is:

````nohighlight
while loading no file, in expression starting on line 0
Segmentation fault (core dumped)```

https://github.com/tastelessjolt/scilab-julia-interface/blob/master/sci_call_julia.c
https://github.com/tastelessjolt/scilab-julia-interface/blob/master/double_conv.c
https://github.com/tastelessjolt/scilab-julia-interface/blob/master/integer_conv.c
````

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 3, 2017, 2:26pm UTC](https://discourse.julialang.org/t/segmentation-error-garbage-collection/4073/2 "2017-06-03T14:26:18Z")

</div>

For one thing, jl\_init and jl\_atexit\_hook can only be called once. It is illegal to call it on every call. GC interaction is described in the embedding doc and from a very breif glance it seems to be ok.

---

<div class="post-metadata">

**Author:** ![tastelessjolt](https://avatars.discourse-cdn.com/v4/letter/t/f14d63/32.png) [@tastelessjolt](https://discourse.julialang.org/u/tastelessjolt)\
**Post date:** [June 5, 2017, 2:18am UTC](https://discourse.julialang.org/t/segmentation-error-garbage-collection/4073/3 "2017-06-05T02:18:34Z")

</div>

Yeah, I tried separating the init and exit calls by adding functions so that jl\_init and jl\_atexit\_hook will be called only once in the lifetime of the program. But still it does give the segmentation error. Since, it gives the segmentation error after calling the function or while it is idle, I couldn’t pinpoint which part of the code is giving the segmentation error.  
So, what might have been going wrong?

Thank you.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 5, 2017, 2:23am UTC](https://discourse.julialang.org/t/segmentation-error-garbage-collection/4073/4 "2017-06-05T02:23:27Z")

</div>

Anything can go wrong. It’s very hard to tell even with the code but if it segfault when julia is not running and it seems that you are not holding any reference to julia object it probably happen either because wrong use of scilab API or conflict in signal handling.

---

<div class="post-metadata">

**Author:** ![tastelessjolt](https://avatars.discourse-cdn.com/v4/letter/t/f14d63/32.png) [@tastelessjolt](https://discourse.julialang.org/u/tastelessjolt)\
**Post date:** [June 5, 2017, 10:05pm UTC](https://discourse.julialang.org/t/segmentation-error-garbage-collection/4073/5 "2017-06-05T22:05:29Z")

</div>

Might be.  
Btw, What do you mean by signal handling?

And also does this help that once the libraries are loaded, the virtual memory becomes ~ 11GB? I know that it doesn’t matter much but just in case.

Thank you.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 5, 2017, 10:32pm UTC](https://discourse.julialang.org/t/segmentation-error-garbage-collection/4073/6 "2017-06-05T22:32:51Z")

</div>

> [@tastelessjolt](#):
>
> Btw, What do you mean by signal handling?

I mean, well, handling signals… Like if scilab uses signals to do something.

> [@tastelessjolt](#):
>
> the virtual memory becomes ~ 11GB

This is expected.

---

<div class="post-metadata">

**Author:** ![tastelessjolt](https://avatars.discourse-cdn.com/v4/letter/t/f14d63/32.png) [@tastelessjolt](https://discourse.julialang.org/u/tastelessjolt)\
**Post date:** [June 12, 2017, 12:20am UTC](https://discourse.julialang.org/t/segmentation-error-garbage-collection/4073/7 "2017-06-12T00:20:29Z")

</div>

And also it is that sometimes just calling the `jl_init` leads to segmentation fault.  
What might lead `jl_init` to a segmentation fault?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 12, 2017, 1:27am UTC](https://discourse.julialang.org/t/segmentation-error-garbage-collection/4073/8 "2017-06-12T01:27:00Z")

</div>

You should get a backtrace. If julia didn’t give you one you should attach a debugger.

---

<div class="post-metadata">

**Author:** ![tastelessjolt](https://avatars.discourse-cdn.com/v4/letter/t/f14d63/32.png) [@tastelessjolt](https://discourse.julialang.org/u/tastelessjolt)\
**Post date:** [June 20, 2017, 2:53am UTC](https://discourse.julialang.org/t/segmentation-error-garbage-collection/4073/9 "2017-06-20T02:53:00Z")

</div>

And update, if I use scilab’s cli, then it works with no problem, but problem is only when I use it with GUI if that helps in some way.
