ecma_destroy_ecma_string (ecma_string_t *string_p) /**< ecma-string */
{
  JERRY_ASSERT (string_p != NULL);
  JERRY_ASSERT (!ECMA_IS_DIRECT_STRING (string_p));
  JERRY_ASSERT ((string_p->refs_and_container < ECMA_STRING_REF_ONE) || ECMA_STRING_IS_STATIC (string_p));

  switch (ECMA_STRING_GET_CONTAINER (string_p))
  {
    case ECMA_STRING_CONTAINER_HEAP_UTF8_STRING:
    {
      ecma_dealloc_string_buffer (string_p, ((ecma_short_string_t *) string_p)->size + sizeof (ecma_short_string_t));
      return;
    }
    case ECMA_STRING_CONTAINER_LONG_OR_EXTERNAL_STRING:
    {
      ecma_long_string_t *long_string_p = (ecma_long_string_t *) string_p;

      if (long_string_p->string_p == ECMA_LONG_STRING_BUFFER_START (long_string_p))
      {
        ecma_dealloc_string_buffer (string_p, long_string_p->size + sizeof (ecma_long_string_t));
        return;
      }

      ecma_external_string_t *external_string_p = (ecma_external_string_t *) string_p;
      jerry_external_string_free_callback_t free_cb = JERRY_CONTEXT (external_string_free_callback_p);

      if (free_cb != NULL)
      {
        free_cb ((lit_utf8_byte_t *) external_string_p->header.string_p,
                 external_string_p->header.size,
                 external_string_p->user_p);
      }

      ecma_dealloc_external_string (external_string_p);
      return;
    }
    case ECMA_STRING_CONTAINER_HEAP_ASCII_STRING:
    {
      ecma_dealloc_string_buffer (string_p, ECMA_ASCII_STRING_GET_SIZE (string_p) + ECMA_ASCII_STRING_HEADER_SIZE);
      return;
    }
#if JERRY_ESNEXT
    case ECMA_STRING_CONTAINER_SYMBOL:
    {
      ecma_extended_string_t *symbol_p = (ecma_extended_string_t *) string_p;
      ecma_free_value (symbol_p->u.symbol_descriptor);
      ecma_dealloc_extended_string (symbol_p);
      return;
    }
#endif /* JERRY_ESNEXT */
    default:
    {
      JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC
                    || ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_MAGIC_STRING_EX);

      /* only the string descriptor itself should be freed */
      ecma_dealloc_string (string_p);
    }
  }
} /* ecma_destroy_ecma_string */
ecma_destroy_ecma_string (ecma_string_t *string_p)  
{
  JERRY_ASSERT (string_p != NULL);
  JERRY_ASSERT (!ECMA_IS_DIRECT_STRING (string_p));
  JERRY_ASSERT ((string_p->refs_and_container < ECMA_STRING_REF_ONE) || ECMA_STRING_IS_STATIC (string_p));

  switch (ECMA_STRING_GET_CONTAINER (string_p))
  {
    case ECMA_STRING_CONTAINER_HEAP_UTF8_STRING:
    {
      ecma_dealloc_string_buffer (string_p, ((ecma_short_string_t *) string_p)->size + sizeof (ecma_short_string_t));
      return;
    }
    case ECMA_STRING_CONTAINER_LONG_OR_EXTERNAL_STRING:
    {
      ecma_long_string_t *long_string_p = (ecma_long_string_t *) string_p;

      if (long_string_p->string_p == ECMA_LONG_STRING_BUFFER_START (long_string_p))
      {
        ecma_dealloc_string_buffer (string_p, long_string_p->size + sizeof (ecma_long_string_t));
        return;
      }

      ecma_external_string_t *external_string_p = (ecma_external_string_t *) string_p;
      jerry_external_string_free_callback_t free_cb = JERRY_CONTEXT (external_string_free_callback_p);

      if (free_cb != NULL)
      {
        free_cb ((lit_utf8_byte_t *) external_string_p->header.string_p,
                 external_string_p->header.size,
                 external_string_p->user_p);
      }

      ecma_dealloc_external_string (external_string_p);
      return;
    }
    case ECMA_STRING_CONTAINER_HEAP_ASCII_STRING:
    {
      ecma_dealloc_string_buffer (string_p, ECMA_ASCII_STRING_GET_SIZE (string_p) + ECMA_ASCII_STRING_HEADER_SIZE);
      return;
    }
#if JERRY_ESNEXT
    case ECMA_STRING_CONTAINER_SYMBOL:
    {
      ecma_extended_string_t *symbol_p = (ecma_extended_string_t *) string_p;
      ecma_free_value (symbol_p->u.symbol_descriptor);
      ecma_dealloc_extended_string (symbol_p);
      return;
    }
#endif  
    default:
    {
      JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_UINT32_IN_DESC
                    || ECMA_STRING_GET_CONTAINER (string_p) == ECMA_STRING_CONTAINER_MAGIC_STRING_EX);

       
      ecma_dealloc_string (string_p);
    }
  }
}  