Skip to content

Commit

Permalink
pyobjus: try reducing the leaks when calling an objc method
Browse files Browse the repository at this point in the history
  • Loading branch information
tito committed Sep 26, 2015
1 parent caac374 commit 6fef6c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pyobjus/pyobjus.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,12 @@ cdef class ObjcMethod(object):
mm = ctypes.cast((<unsigned long *>f_args[f_index])[0], ctypes.POINTER(ctypes.c_uint32))
ret_py_val.add_reference_return_value(mm.contents, CArrayCount)

# free f_args
for index, arg in enumerate(args):
print "free(1)", <unsigned long>f_args[index + 2]
free(f_args[index + 2])
free(f_args)

return ret_py_val

registers = []
Expand Down
6 changes: 3 additions & 3 deletions pyobjus/pyobjus_conversions.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,8 @@ cdef void* convert_py_arg_to_cy(arg, sig, by_value, size_t size) except *:
(<int*>val_ptr)[0] = 0

# TODO: Find best time to dealloc memory used by this pointer
#if arg_val_ptr != NULL and del_arg_val_ptr:
# free(arg_val_ptr)
# arg_val_ptr = NULL
if arg_val_ptr != NULL and del_arg_val_ptr:
free(arg_val_ptr)
arg_val_ptr = NULL

return val_ptr
3 changes: 3 additions & 0 deletions pyobjus/pyobjus_types.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,9 @@ cdef class ObjcClassInstance:
self.resolve_methods()
self.resolve_fields()

def get_address(self):
return <unsigned long><void *>self.o_instance

def __getattribute__(self, name):

if isinstance(object.__getattribute__(self, name), ObjcProperty):
Expand Down

0 comments on commit 6fef6c0

Please sign in to comment.