<p dir="auto">Looping through and reading 50k Nodes &amp; their properties using the Java API leaks badly when read-_only mode is set on the source.</p>
<p dir="auto">Below is my code (apologies for being ugly - I've been trying to find this for hours). Un-comment the ".setConfig( GraphDatabaseSettings.read_only, "true" )" to watch it leak. Eclipse MAT had 400k NeoStoreTransactions occupying 1.1GB.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
public class Main {
    static GraphDatabaseService graphSrc ;
    static BatchInserter graphDest ;

    public static void main(String[] args) {
        Runtime.getRuntime().addShutdownHook( new Thread() {
            @Override
            public void run() {
                if (graphDest!=null)
                    graphDest.shutdown();
                if (graphSrc!=null)
                    graphSrc.shutdown();
            }
        });

        String src = args[0] ;

        graphSrc = new GraphDatabaseFactory()
        .newEmbeddedDatabaseBuilder( src )
        .loadPropertiesFromFile(&quot;neo4j.properties&quot; )
        //      .setConfig( GraphDatabaseSettings.read_only, &quot;true&quot; )
        //      .setConfig( GraphDatabaseSettings.cache_type, &quot;none&quot; )
        .newGraphDatabase();

        //graphDest = BatchInserters.inserter(src+&quot;.copy&quot;);

        copyNodes() ;
    }

    static final Label[] labels = new Label[0] ;
    static List&lt;Label&gt; alLabels = new ArrayList&lt;Label&gt;() ;

    static Label[] labels(Node n) {
        alLabels.clear();
        for (Label x:n.getLabels()) {
            alLabels.add(x) ;
        }
        return alLabels.toArray(labels) ;
    }

    static Map&lt;String,Object&gt; getProps(PropertyContainer src) {
        HashMap&lt;String,Object&gt; props = new HashMap&lt;String,Object&gt;() ;
        try (Transaction txInner = graphSrc.beginTx()) {
            for (String key:src.getPropertyKeys()) {
                props.put(key, src.getProperty(key));
            }
            txInner.success(); 
            txInner.close();
        }
        return props ;
    }

    static void copyNodes() {
        int nodes = 0 ;
        ArrayList&lt;Long&gt; ids = new ArrayList&lt;Long&gt;() ;
        Iterable&lt;Node&gt; srcNodes ;

        try (Transaction tx = graphSrc.beginTx()) {
            srcNodes = GlobalGraphOperations.at(graphSrc).getAllNodes() ;
            for (Node src:srcNodes) {
                Map&lt;String,Object&gt; props = getProps(src) ;
                //graphDest.createNode(src.getId(), props, labels(src));
                ids.add(src.getId()) ;

                if ((nodes%1000)==0) {
                    System.out.print(&quot;\r&quot;+nodes+&quot; nodes copied. &quot;+Runtime.getRuntime().freeMemory());
                    System.gc() ;
                }
                nodes += 1 ;
            }
            tx.success();
            tx.close();
        }
    }
}

"><pre class="notranslate"><code class="notranslate">
public class Main {
    static GraphDatabaseService graphSrc ;
    static BatchInserter graphDest ;

    public static void main(String[] args) {
        Runtime.getRuntime().addShutdownHook( new Thread() {
            @Override
            public void run() {
                if (graphDest!=null)
                    graphDest.shutdown();
                if (graphSrc!=null)
                    graphSrc.shutdown();
            }
        });

        String src = args[0] ;

        graphSrc = new GraphDatabaseFactory()
        .newEmbeddedDatabaseBuilder( src )
        .loadPropertiesFromFile("neo4j.properties" )
        //      .setConfig( GraphDatabaseSettings.read_only, "true" )
        //      .setConfig( GraphDatabaseSettings.cache_type, "none" )
        .newGraphDatabase();

        //graphDest = BatchInserters.inserter(src+".copy");

        copyNodes() ;
    }

    static final Label[] labels = new Label[0] ;
    static List&lt;Label&gt; alLabels = new ArrayList&lt;Label&gt;() ;

    static Label[] labels(Node n) {
        alLabels.clear();
        for (Label x:n.getLabels()) {
            alLabels.add(x) ;
        }
        return alLabels.toArray(labels) ;
    }

    static Map&lt;String,Object&gt; getProps(PropertyContainer src) {
        HashMap&lt;String,Object&gt; props = new HashMap&lt;String,Object&gt;() ;
        try (Transaction txInner = graphSrc.beginTx()) {
            for (String key:src.getPropertyKeys()) {
                props.put(key, src.getProperty(key));
            }
            txInner.success(); 
            txInner.close();
        }
        return props ;
    }

    static void copyNodes() {
        int nodes = 0 ;
        ArrayList&lt;Long&gt; ids = new ArrayList&lt;Long&gt;() ;
        Iterable&lt;Node&gt; srcNodes ;

        try (Transaction tx = graphSrc.beginTx()) {
            srcNodes = GlobalGraphOperations.at(graphSrc).getAllNodes() ;
            for (Node src:srcNodes) {
                Map&lt;String,Object&gt; props = getProps(src) ;
                //graphDest.createNode(src.getId(), props, labels(src));
                ids.add(src.getId()) ;

                if ((nodes%1000)==0) {
                    System.out.print("\r"+nodes+" nodes copied. "+Runtime.getRuntime().freeMemory());
                    System.gc() ;
                }
                nodes += 1 ;
            }
            tx.success();
            tx.close();
        }
    }
}


</code></pre></div>
<p dir="auto">Output with read_only = false ;</p>
<p dir="auto">0 nodes copied. 953752000<br>
1000 nodes copied. 987284312<br>
2000 nodes copied. 1002276640<br>
3000 nodes copied. 1012237096<br>
4000 nodes copied. 1011354664<br>
5000 nodes copied. 1010389912<br>
6000 nodes copied. 1009443688</p>
<p dir="auto">Output with read_only = true ;</p>
<p dir="auto">0 nodes copied. 975316912<br>
1000 nodes copied. 903150600<br>
2000 nodes copied. 861072744<br>
3000 nodes copied. 818662472<br>
4000 nodes copied. 767496136<br>
5000 nodes copied. 715829648<br>
6000 nodes copied. 667054608</p>
<p dir="auto">I'm running the neo4j rest server on small ARM systems, as described here:<br>
<a href="https://github.com/cjdaly/napkin/wiki/Server-on-BeagleBone-black">https://github.com/cjdaly/napkin/wiki/Server-on-BeagleBone-black</a></p>
<p dir="auto">I recently moved from 1.9.x to 2.0M6.  Initially I just got things to work by updating my cypher usage to stop using the old ? and ! syntax.  Was able to run like this for several days with no issues.  Then I added an index like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="CREATE INDEX ON :NAPKIN(`napkin.segment`)"><pre class="notranslate"><code class="notranslate">CREATE INDEX ON :NAPKIN(`napkin.segment`)
</code></pre></div>
<p dir="auto">and reworked my cypher to use the :NAPKIN label.  With this change, neo4j becomes unstable in less than a day.</p>
<p dir="auto">I'm using values in neo4j-wrapper.conf that correspond to -Xmx96m -Xms96m. The neo4j linux process seems to consume increasing (VmPeak) memory over time.</p>
<p dir="auto">I have more details and a link to the Neo4j log with exception stacks here: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="21805679" data-permission-text="Title is private" data-url="https://github.com/cjdaly/napkin/issues/2" data-hovercard-type="issue" data-hovercard-url="/cjdaly/napkin/issues/2/hovercard" href="https://github.com/cjdaly/napkin/issues/2">cjdaly/napkin#2</a></p>