# Opaque pointers and ccall mem. management

**URL:** <https://discourse.julialang.org/t/opaque-pointers-and-ccall-mem-management/29081>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 23, 2019, 4:47pm UTC](https://discourse.julialang.org/t/opaque-pointers-and-ccall-mem-management/29081 "2019-09-23T16:47:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [September 23, 2019, 4:47pm UTC](https://discourse.julialang.org/t/opaque-pointers-and-ccall-mem-management/29081/1 "2019-09-23T16:47:03Z")

</div>

1. What is the recommended julia side of C-API opaque pointer? I’d like to have a julia type for it. z1 = ccall((lib, allocateNewO), Ptr{NewO},(Uint64, ), newNumber); with NewO without structure.

2. Can julia be convinced NOT to free all fields of a struct in GC? I have code that contains something like this

```julia
mutable struct InterpreterHooks <: GraphicsDevice
	closure::Ptr{Nothing} 
	surface_create::Ptr{Nothing} 
	surface_destroy::Ptr{Nothing}
	context_create::Ptr{Nothing} 
	context_destroy::Ptr{Nothing}
	show_page::Ptr{Nothing} 
	copy_page::Ptr{Nothing} 
	create_source_image::Ptr{Nothing} 
end

```

and to closure a Ptr{Nothing} is assigned, that is a pointer to a ‘context’ and it has an own finalizer. However, when GC frees an instance of InterpreterHooks it (at least that’s the story gdb+rr tells me) it frees all pointers inside it also.
