detect_destroy(3)

πŸ“¦
version 1.0.6 Β· 3 versions
, in arch rolling, debian trixie, nixos 26.05, nixpkgs unstable, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– detect_destroy β€” free Detector structure πŸ’–

okay bestie, this is page three of the libchardet library functions manual, and honestly? it's a short one, but it's SO important. it's giving cleanup era. ✨


🌸 NAME 🌸

detect_destroy β€” free Detector structure

like, it frees the Detector structure. that's the whole job. and it ate. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <chardet.h>

void detect_destroy (Detect ** handle);

that's it. one function, one argument, no return. lowkey iconic for being so simple. πŸ¦‹


✨ DESCRIPTION ✨

Free resource that allocated by detect_init api.

so basically β€” remember that memory your girl detect_init handed you? the one you've been holding onto this whole time? yeah. this is where you give it back. detect_destroy frees the resource that was allocated by the detect_init api. no cap. πŸ”₯

not you forgetting to call this and leaking memory... couldn't be you bestie. please call it. πŸ™ˆ

πŸ’œ RETURN VALUE πŸ’œ

void

she returns nothing. she gives nothing back. she just takes the memory away and leaves. main character energy fr fr. πŸ‘‘


🌈 EXAMPLE 🌈

here's the whole vibe in code, exactly as it goes:

#include <chardet.h>

int main (void) {
     Detect    * d;
     DetectObj * obj;

     if ( (d = detect_init ()) == NULL ) {
          fprintf (stderr, "chardet handle initialize failed\n");
          return CHARDET_MEM_ALLOCATED_FAIL;
     }

     detect_reset (&d);

     if ( (obj = detect_obj_init ()) == NULL ) {
          fprintf (stderr, "Memory Allocation failed\n");
          return CHARDET_MEM_ALLOCATED_FAIL;
     }

     switch (detect_handledata (&d, "μ•ˆλ…•ν•˜μ„Έμš”", &obj)) {
          case CHARDET_OUT_OF_MEMORY :
               fprintf (stderr, "On handle processing, occured out of memory\n");
               detect_obj_free (&obj);
               return CHARDET_OUT_OF_MEMORY;
          case CHARDET_NULL_OBJECT :
               fprintf (stderr,
                         "3st argument of chardet_handledata() is must memory allocation "
                         "with detect_obj_init API\n");
               return CHARDET_NULL_OBJECT;
     }

     # check support obj->bom with CHARDET_BOM_CHECK constant
     printf ("encoding: %s, confidence: %f, exists bom: %d\n", obj->encoding, obj->confidence, obj->bom);
     detect_obj_free (&obj);
     detect_destroy (&d);

    return 0;
}

see how detect_destroy (&d); shows up right at the end, after detect_obj_free (&obj);? that's the order bestie. clean up the obj, then clean up the handle. the way that it all comes full circle... 🫢


🧚 AUTHORS 🧚

JoungKyun.Kim <http://oops.org>

ty for your service king 🫑


πŸ’€ BUG REPORTS πŸ’€

Use QnA board on https://github.com/Joungkyun/libchardet/issues

found something cursed? take it there, don't suffer in silence. 🌸


πŸ¦‹ SEE ALSO πŸ¦‹

detect_init(3), detect_reset(3)


and that's the page!! this lil slice of the libchardet manuals is dated 2019-08-01, and it lives under the Library Functions Manual umbrella. periodt. πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from