title: Woocommerce - Hight memory usage when programmatically updating product variations
body: <p>I need to programmatically update about 7000 product variations.</p>
  
  <p>I have tried several solutions and best performance I got with this (thanks to <a href="https://wordpress.stackexchange.com/questions/189371/how-to-solve-suspected-memory-issue-in-custom-wordpress-loop">https://wordpress.stackexchange.com/questions/189371/how-to-solve-suspected-memory-issue-in-custom-wordpress-loop</a>):</p>
  
  <pre><code>&lt;?php
  
  require_once("wp-load.php");
  
  $dealer_file = json_decode(file_get_contents('file.json'), true);
  
  $args = array(
      'fields'         =&gt; 'ids',
      'posts_per_page' =&gt; 10, 
      'post_type'      =&gt; array('product_variation'),
      'post_status'    =&gt; 'publish',
  );
  
  $query = new WP_Query;
  $paged = 1;
  $count = 0;
  $total = null;
  
  do {
      $args['no_found_rows'] = isset( $total );
      $args['paged'] = $paged++;
  
      $post_ids = $query-&gt;query( $args );
      update_postmeta_cache( $post_ids );
  
      if ( ! isset( $total ) )
          $total = $query-&gt;found_posts;
  
      $count += $query-&gt;post_count;
  
      foreach ( $post_ids as $post_id ) {
          $sku = get_post_meta( $post_id, '_sku', true );
  
          if(!empty($sku)) {
              if ( array_key_exists( $sku, $dealer_file ) ) {
                  wc_update_product_stock( $post_id, $dealer_file[ $sku ]['stock_info'] );
                  echo memory_get_usage(true).'&lt;br&gt;';
              }
              else {
                  //Log function
              }
          }
  
          // Wipe this post's meta from memory
          wp_cache_delete( $post_id, 'posts' );
          wp_cache_delete( $post_id, 'post_meta' );
      }
  
  } while ( $count &lt; $total );
  
  ?&gt;
  </code></pre>
  
  <p>With this method I'm using about 600MB of memory (with my code it was 800MB).
  I have upgraded to PHP 7.
  Is there a way to reduce memory usage further more?</p>