Let $(X,\mu)$ be a $\sigma$-finite measure space. When does $g\in L^\infty(X,\mu)$ define a compact operator on $L^2(X,\mu)$? Suppose we have a $\sigma$-finite measure $(X,\mu)$. In the case that I am given, we actually have that $X$ is a locally compact Hausdorff space and that $\mu$ is a Radon measure, though this may be more than necessary. Consider for every $g\in L^\infty(X,\mu)$ the bounded operator $M_g\in\mathscr{L}(L^2(X,\mu))$ defined as $$M_g:f\mapsto fg.$$
Then is there any necessary/sufficient/necessary and sufficient condition that we can place on $g$ that guarantees that $M_g$ is a compact operator?
I can solve this in the specific case that $(X,\mu)$ is $\mathbb{N}$ with the counting measure – in this case $g\in\ell^\infty(\mathbb{N})$ defines a compact operator iff $\lim_{n\to\infty}g(n)=0$. However, it is not true that for any $g\in L^\infty(X,\mu)$, it is sufficient that $$g(x)\xrightarrow{x\to\infty}0$$ in the sense of the one point compactification $X\cup\{\infty\}$, as th simple example of $X=[0,1]$ shows.
 A: Let us say a measurable subset $A\subseteq X$ is atomic if $L^2(A,\mu|_A)$ is finite-dimensional, or equivalently if $A$ has only finitely many different measurable subsets modulo null sets (so it is a finite union of atoms of the measure $\mu$).  The necessary and sufficient condition for $M_g$ to be compact is then that for all $\epsilon>0$, $A_\epsilon=\{x\in X:|g(x)|>\epsilon\}$ is atomic.
Indeed, suppose $A_\epsilon$ is atomic for all $\epsilon>0$.  Define $g_\epsilon(x)=g(x)$ for $x\in A_\epsilon$ and $g_\epsilon(x)=0$ otherwise.  Then $\|M_{g_\epsilon}-M_g\|=\|M_{g-g_\epsilon}\|\leq \epsilon$, since $|g(x)-g_\epsilon(x)|\leq\epsilon$ for all $x$.  On the other hand, the operator $M_{g_\epsilon}$ has finite rank, since its image consists of functions supported on $A_\epsilon$ and $A_\epsilon$ is atomic.  So $M_g$ can be approximated by finite rank operators, and hence is compact.
Conversely, suppose $A_\epsilon$ is not atomic for some $\epsilon>0$.  Let $P$ be the orthogonal projection onto the subspace $L^2(A_\epsilon,\mu|_{A_\epsilon})\subseteq L^2(X,\mu)$; explicitly, $P=M_{1_{A_\epsilon}}$.  Note that $PM_gP$ is an invertible operator on $L^2(A_\epsilon,\mu|_{A_\epsilon})$, with inverse $M_{g^{-1}}$ (which is bounded since $|g(x)|>\epsilon$ everywhere on $A_\epsilon$).  Since $L^2(A_\epsilon,\mu|_{A_\epsilon})$ is infinite-dimensional, $PM_gP$ is therefore not compact, and so neither is $M_g$.
