Start Android Studio. Close any open project.Go to File > Othersettings > DefaultSettings.(a window will open)
On Settings dialog,select Android Compilers under Built, Execution, Deployment > Compiler and set VM Options to -Xmx512m(i.e. write -Xmx512m under VM Options:) and press OK.
Remove the .gradle directory (my location was C:\Users\UserName\.gradle), and restart android studio. It will automatically create a new one.
Add an environment variable by going in mycomputer>properties>advance system settings like
There select environment variable and add GRADLE_OPTS with the value of -Dorg.gradle.jvmargs=-Xmx512m as like below
Hope this also help.