title: Wordpress theme memory leak
body: <p>I'm developing a custom wordpress theme for one of my clients and I encounter several <code>memory exhausted</code> errors.</p>
  
  <p>At this moment I have set the available memory at 64mb and even I can set this higher but I don't want to do this; but optimize my work. Also the client insists to use two plugins (Visual Composer &amp; Ultimate Addons for Visual Composer) that takes some more memory.</p>
  
  <p>My question is:
  How can I see what queries, objects, variables use the memory and how I can free those.</p>
  
  <p>I tried a bunch of plugins (Debug Bar, Memory Viewer, p3, Query Monitor) but they only tell me how much memory I use and nothing specific.</p>
  
  <p>Can you point me to some articles about this subject (I searched for two days but nothing clear was returned about this subject).</p>
  
  <p>Most of the memory errors appear after I make ajax calls. Is there something I can do to prevent memory overload in the PHP function?</p>
  
  <p>Any advice is appreciated.</p>
  
  <p>Thanks</p>
  
  <p>Here is the code where the memory leak happens - However the problem is somewhere around wp_head execution. My investigations reveal a jump in memory use at that time. The question is about general guidelines and things to do in case you need to debug these kind of issues.
      // $args is printed</p>
  
  <pre><code>Array
  (
  [post_type] =&gt; estate_property
  [post_status] =&gt; publish
  [paged] =&gt; 1
  [posts_per_page] =&gt; 30
  [meta_key] =&gt; prop_featured
  [orderby] =&gt; meta_value
  [order] =&gt; DESC
  [meta_query] =&gt; Array
      (
          [0] =&gt; Array
              (
                  [key] =&gt; property_price
                  [value] =&gt; 0
                  [type] =&gt; numeric
                  [compare] =&gt; &gt;=
              )
  
          [1] =&gt; Array
              (
                  [key] =&gt; property_price
                  [value] =&gt; 50000000
                  [type] =&gt; numeric
                  [compare] =&gt; &lt;=
              )
  
      )
  
  [cache_results] =&gt; 
  [tax_query] =&gt; Array
      (
          [relation] =&gt; AND
          [0] =&gt; 
          [1] =&gt; 
          [2] =&gt; 
          [3] =&gt; 
          [4] =&gt; 
      )
  
  )
  
  
  $prop_selection =   new WP_Query($args);
  </code></pre>
  
  <p>.....</p>