diff --git a/cmd/flags.go b/cmd/flags.go
index 93b5d505d77f4846f80d1cda6b32bfa29a0ad3cf..096c92d792b002457173a69c27aff68042e5ad63 100644
--- a/cmd/flags.go
+++ b/cmd/flags.go
@@ -80,6 +80,7 @@ const (
 	// Misc
 	sendIdFlag       = "sendid"
 	profileCpuFlag   = "profile-cpu"
+	profileMemFlag   = "profile-mem"
 	userIdPrefixFlag = "userid-prefix"
 
 	///////////////// Broadcast subcommand flags //////////////////////////////
diff --git a/cmd/root.go b/cmd/root.go
index 837b68e1af7d13f8476844c3bb0f525be4bcbd63..3766d7cb53360d19598066788aaa42726c10aa2b 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -17,7 +17,9 @@ import (
 	"io/ioutil"
 	"log"
 	"os"
-	"runtime/pprof"
+
+	"github.com/pkg/profile"
+
 	"strconv"
 	"strings"
 	"sync"
@@ -58,13 +60,17 @@ var rootCmd = &cobra.Command{
 	Short: "Runs a client for cMix anonymous communication platform",
 	Args:  cobra.NoArgs,
 	Run: func(cmd *cobra.Command, args []string) {
-		profileOut := viper.GetString(profileCpuFlag)
-		if profileOut != "" {
-			f, err := os.Create(profileOut)
-			if err != nil {
-				jww.FATAL.Panicf("%+v", err)
-			}
-			pprof.StartCPUProfile(f)
+		cpuProfileOut := viper.GetString(profileCpuFlag)
+		if cpuProfileOut != "" {
+			defer profile.Start(profile.CPUProfile,
+				profile.ProfilePath(cpuProfileOut),
+				profile.NoShutdownHook).Stop()
+		}
+		memProfileOut := viper.GetString(profileMemFlag)
+		if memProfileOut != "" {
+			defer profile.Start(profile.MemProfile,
+				profile.ProfilePath(memProfileOut),
+				profile.NoShutdownHook).Stop()
 		}
 
 		cmixParams, e2eParams := initParams()
@@ -382,9 +388,6 @@ var rootCmd = &cobra.Command{
 				"Failed to cleanly close threads: %+v\n",
 				err)
 		}
-		if profileOut != "" {
-			pprof.StopCPUProfile()
-		}
 		jww.INFO.Printf("Client exiting!")
 	},
 }
@@ -1101,6 +1104,10 @@ func init() {
 		"Enable cpu profiling to this file")
 	viper.BindPFlag(profileCpuFlag, rootCmd.Flags().Lookup(profileCpuFlag))
 
+	rootCmd.Flags().String(profileMemFlag, "",
+		"Enable memory profiling to this file")
+	viper.BindPFlag(profileMemFlag, rootCmd.Flags().Lookup(profileMemFlag))
+
 	// Proto user flags
 	rootCmd.Flags().String(protoUserPathFlag, "",
 		"Path to proto user JSON file containing cryptographic primitives "+
diff --git a/go.mod b/go.mod
index f6badba6d5e8ec6dc357d50d7d8fd1140227cc49..c6f83e6879e7e1f6b1f2c64491ad08c2a4d8e9d5 100644
--- a/go.mod
+++ b/go.mod
@@ -39,6 +39,7 @@ require (
 	github.com/mitchellh/mapstructure v1.5.0 // indirect
 	github.com/pelletier/go-toml v1.9.5 // indirect
 	github.com/pelletier/go-toml/v2 v2.0.2 // indirect
+	github.com/pkg/profile v1.6.0 // indirect
 	github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
 	github.com/spf13/afero v1.9.2 // indirect
 	github.com/spf13/cast v1.5.0 // indirect
diff --git a/go.sum b/go.sum
index 05b8e2f0eff1eae4e7065f63368705354b9a0d58..e4ee81f844c49c44c4881b7f3e3b9c370cf9b53f 100644
--- a/go.sum
+++ b/go.sum
@@ -335,6 +335,8 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
 github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pkg/profile v1.6.0 h1:hUDfIISABYI59DyeB3OTay/HxSRwTQ8rB/H83k6r5dM=
+github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18=
 github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=