GitHub user techaddict opened a pull request:
https://github.com/apache/spark/pull/15843
[SPARK-18274] Memory leak in PySpark StringIndexer
## What changes were proposed in this pull request?
Make Java Gateway dereference object in destructor, using
`SparkContext._gateway.detach` inside`JavaWrapper`'s destructor
## How was this patch tested?
```scala
import random, string
from pyspark.ml.feature import StringIndexer
l = [(''.join(random.choice(string.ascii_uppercase) for _ in range(10)), )
for _ in range(int(7e5))] # 700000 random strings of 10 characters
df = spark.createDataFrame(l, ['string'])
for i in range(50):
indexer = StringIndexer(inputCol='string', outputCol='index')
indexer.fit(df)
```
Before: would keep StringIndexer strong reference, causing GC issues and is
halted midway
After: garbage collection works as the object is dereferenced, and
computation completes
Testing using profiler
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/techaddict/spark SPARK-18274
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/15843.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #15843
----
commit a493c1961829000986446db11ce67f3103a79bea
Author: Sandeep Singh <[email protected]>
Date: 2016-11-10T16:16:13Z
[SPARK-18274] Memory leak in PySpark StringIndexer
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]