Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6381401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:23:25+00:00 2026-05-25T02:23:25+00:00

There is something that confuses me. Let there be a class member Foo::$bar ,

  • 0

There is something that confuses me. Let there be a class member
Foo::$bar, which has to be initialized as an empty array in the
constructor. If I do that (via zend_update_property), its refcount is
increased (from 1, which it gets after alloc + array_init, to 2). It is
obvious why this happens, since from zend_update_property‘s perspective, it gets a
variable from somone in the outside world, and so it is right to ++ it.

But in this particular case, the array being initialized in the
constructor, it does not need a refcount of 2, 1 is right, since it’s
used only by the object (yet).

So I thought I will Z_DELREF_P() it. And it worked. Until I started
valgrind, which was reporting:

==4538== Invalid read of size 4
==4538==    at 0x822D3C6: _zval_ptr_dtor (zend.h:385)
==4538==    by 0x823C1FF: _zval_ptr_dtor_wrapper (zend_variables.c:189)
==4538==    by 0x824E1A1: zend_hash_destroy (zend_hash.c:529)
==4538==    by 0x826655A: zend_object_std_dtor (zend_objects.c:45)
==4538==    by 0x8266A28: zend_objects_free_object_storage 
(zend_objects.c:126)
==4538==    by 0x826C43D: zend_objects_store_del_ref_by_handle_ex 
(zend_objects_API.c:220)
==4538==    by 0x826C0AC: zend_objects_store_del_ref 
(zend_objects_API.c:172)
==4538==    by 0x823BD77: _zval_dtor_func (zend_variables.c:52)
==4538==    by 0x822B99B: _zval_dtor (zend_variables.h:35)
==4538==    by 0x822D463: _zval_ptr_dtor (zend_execute_API.c:443)
==4538==    by 0x823C1FF: _zval_ptr_dtor_wrapper (zend_variables.c:189)
==4538==    by 0x824E518: zend_hash_apply_deleter (zend_hash.c:614)
==4538==  Address 0x44c1718 is 8 bytes inside a block of size 20 free'd

which happens when the engine destroys the object (when the object runs out of scope – the destructor is also called).

So it looks like the ZE really needs the refcount to be 2. All other
tests I’ve written work fine, no memleaks, no segfaults whatsoever.

Still I am a little bit confused: WHY does it need it be higher than
(from my understanding) it should be?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:23:25+00:00Added an answer on May 25, 2026 at 2:23 am

    @hakre’s question made me think.

    The explanation is the following: when the ZE destroys the object, it also destroys (zval_ptr_dtor) each property of the object. So it is right to have a refcount of 1 after the destructor was called, which is what I have currently, since I also call zval_ptr_dtor on that specific property decreasing its refcount from 2 to 1.

    The ZE will take care of the rest.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

there is something that confuses me a little bit and i would like some
cgi.escape seems like one possible choice. Does it work well? Is there something that
Is there something available that could help me convert a XSD into SQL relational
If there's something that everybody hates about Magento it's endlessly configuring your modules before
I am playing with the .net remoting features and there is something that I
I have many requires and includes and i was wondering if there's something that
math.h is not really a documentation. Is there something else that will describe these
Is there something like InstallShield that I can use for free?
I know websphere does it, so there must be something that lets apache figure
Is there something like a panel that I can use in a MFC application.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.