Q:

CasperJS crashes - can they be avoided with refresh or reinstance?

hope you're having an awesome day.
I'm running a CasperJS scrape across around 100,000 links over the course of a few days (continuously). 
For every 500 or so, casperJS crashes randomly. When reloaded and started from the last link, however, it continues for another 500.
I was wondering if someone knows of an effective way I might be able to refresh or close & reinstance casperjs, to avoid this burnout? I was thinking of an exit() paired with a wait, but very keen on thoughts!
The script is similar to: 
var casper = require('casper').create({
  verbose: true,
  logLevel: 'error',
  pageSettings: {
    loadImages: false,
    loadPlugins: true,
    userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11'
  },
  clientScripts: ['vendor/jquery.min.js', 'vendor/lodash.js'],
 viewportSize: {
    width: 1600,
    height:1000
  }
});

var linkArray = [ // Includes 100,000 + links ]

function inspectUrl(url) {
    casper.thenOpen(url, function() {
        title = this.getPageTitle();
        bodyText = this.fetchText('body');

        // Includes a bunch of other tasks to do.
}

casper.start('https://www.google.com.au', function() {
    console.log('Booting up CasperJS...');
});

casper.then(function() {
    for (var i = 0; i < linkArray.length; i++) {
        inspectUrl(linkArray[i]);
    };
});

casper.run()

A:

There is a known PhantomJS memory problem. You should develop a "runner", which runs your CasperJS script with some 400 links, collects result, then runs another instance of the script with another portion of links and so far.
Maybe you can make some CasperJS instances run in parallel, if you need speed.
You can develop such a runner with PhantomJS, using the spawn function.
The function is described briefly in the PhantomJS docs: http://phantomjs.org/api/child_process/
UPDATE:
You can find below a working example of such a runner. The example is very simple, just to demonstrate how one could spawn CasperJS instances and collect their results. In particular, there is no error handling in the example at all. The example have been tested with PhantomJS 2.1.1.
The runner uses Q promises, so first you have to make file package.json with the following content:
{
    "dependencies": {
        "q": "1.4.1"
    }
}

and run installer:

npm install

Then you have to create runner.js: 
var Q = require('q');
var childProcess = require('child_process');

var parserTasks = [
    'http://phantomjs.org/',
    'http://casperjs.org/',
    'https://jquery.com/'
];

run(parserTasks).then(function(result) {
    console.log('Tasks result: ' + JSON.stringify(result));
    phantom.exit();
});

function run(tasks) {
    if (tasks.length) {
        var task = tasks.pop();
        return runTask(task).then(function(result) {
            console.log('result: ' + result);
            return run(tasks).then(function(results) {
                return([result].concat(results));
            });
        });
    } else {
        return Q([]);
    }
}

function runTask(task) {
    var defer = Q.defer();

    var spawn = childProcess.spawn;
    var result = '';
    var child = spawn('casperjs', ['parser.js', task]);
    console.log("spawn run: " + task);
    child.stdout.on("data", function(data) {
        result += data;
    });
    child.on("exit", function() {
        defer.resolve(result);
    });

    return defer.promise;
}

and parser.js
var casper = require('casper').create();

var url = casper.cli.args[0];

var result;

casper.start();

casper.thenOpen(url, function() {
    result = this.getTitle();
});

casper.run(function() {
    this.echo(result).exit();
});

You could execute the runner the following way, meaning that phantomjs executable is somewhere on PATH.

phantomjs runner.js

The output should be the following:
spawn run: https://jquery.com/
result: jQuery

spawn run: http://casperjs.org/
result: CasperJS, a navigation scripting and testing utility for PhantomJS and SlimerJS

spawn run: http://phantomjs.org/
result: PhantomJS | PhantomJS

Tasks result: ["jQuery\n","CasperJS, a navigation scripting and testing utility for PhantomJS and SlimerJS\n","PhantomJS | PhantomJS\n"]

