You have the following methods of the `$wpdb` object:

 -   `$wpdb->flush()` that contains a call to `mysqli_free_result()` or `mysql_free_result()` if not supported. 

 -   `$wpdb->check_connection()` that contains a call to `mysqli_ping()` or `mysql_ping()` if not supported. 

You can of course use all your PHP functions in WordPress.

Here's an untested example:

    // Use the global instance created by WordPress
    global $wpdb;

    // Fetch our data with some huge query:
    $results = $wpdb->get_results( "SELECT * FROM {$wpdb->posts}" );    

    // ... some data handling here

    // Let's flush for another huge query.
    // But that's not actually needed, 
    // since this is already done in the $wpdb->query() call
    // that's used within the $wpdb->get_results() method.
    $wpdb->flush();

    // Check the connection:
    if( ! $wpdb->check_connection( $allow_bail = false ) ) 
    {
       // Let's try to connect again:
       if( ! $wpdb->db_connect( $allow_bail = false ) )
       {
            wp_die( sprintf( '<pre>%s<pre>', __( 'No DB connection' ) ) );
       }        
    }

    // Fetch another set of data:
    $results = $wpdb->get_results( "SELECT * FROM {$wpdb->users}" );    

Notice that in most cases, we don't need to create custom SQL queries with `$wpdb`. 

We can get very far by simply using the `WP_Query`, `WP_Comment_Query` or `WP_User_Query` classes. They can help us generate complex SQL queries that are executed through the `$wpdb->get_results()` or `$wpdb->get_col()` calls. 

For the `WP_Query` case, this happens in the humongous `WP_Query::get_posts()` method. 

So there we already have `$wpdb->flush()` calls.