Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

270
Vistas
IOS removes allocated memory in native library

Strange behavior in IOS while integrating with a c/c++ library.

In AppDelegate i call

 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND,0), ^{
    [[ABCService sharedInstance] abcInitialize];
});

abcInitialize is defined in c++ library

struct abc *top;
top = calloc(TYPE_SERV,size_of(struct abc));
top->us = server_alloc (...certain_params...);

inside server alloc i do alloc of structures struct1 and struct2 And then in Initialize function i try to access

top->us = calloc(TYPE_US, size_of(struct us));
if(top->us->struct1) //do something

I noticed that my struct1 is always null

When i debugged, i can see that the structure was allocated fine and values are set appropriately, but before returning from the function, the memory is automatically deallocated. This is totally confusing and annoying. Could any one help me understand what is going on?

I tried by turning off ARC too, still no change

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

top->us = calloc(TYPE_US, size_of(struct us));
if(top->us->struct1) //do something 

I noticed that my struct1 is always null

If that's your real code, then yes, struct1 will always be null. calloc allocates memory and initializes it to zero. Hence, all of the members of top->us will be zero, and since struct1 is a member of top->us, it's going to be zero, i.e. NULL.

over 4 years ago · Santiago Trujillo Denunciar

0

First of all, ARC has nothing to do with memory management of C or C++ codes, so, you can rule out ARC for causing this.

According to http://www.cplusplus.com/reference/cstdlib/calloc/, calloc always initialize all the bits of the allocated memory to 0, naturally, top->us->struct1 will be NULL.

but before returning from the function, the memory is automatically deallocated

How do you come to the conclusion that the memory is automatically deallocated? As mentioned above, ARC will not automatically release your C++ structure/object.

As a conclusion. The result you saw was indeed as expected.

over 4 years ago · Santiago Trujillo Denunciar

0

I found the issue and it was due to linking the same file twice from different library. I have corrected my libraries and that had fixed my issue. So no source code was updated. Just the libs were corrected with the right sources. Thanks a lot of for your support.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda